当前位置: 首页>>代码示例>>C#>>正文


C# IBasicProperties.GetDataContractKey方法代码示例

本文整理汇总了C#中IBasicProperties.GetDataContractKey方法的典型用法代码示例。如果您正苦于以下问题:C# IBasicProperties.GetDataContractKey方法的具体用法?C# IBasicProperties.GetDataContractKey怎么用?C# IBasicProperties.GetDataContractKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IBasicProperties的用法示例。


在下文中一共展示了IBasicProperties.GetDataContractKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleBasicDeliver

        public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body)
        {
            DataContractKey dataContractKey = properties.GetDataContractKey();

            string sBody = _encoding.GetString(body);

            RawBusMessage rawBusMessage = _messageHelper.ConstructMessage(dataContractKey, properties, (object)sBody);

            try
            {
                _monitor(rawBusMessage);
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {

            }
        }
开发者ID:ronybot,项目名称:MessageBus,代码行数:18,代码来源:MessageMonitorConsumer.cs

示例2: ConsumeMessage

        protected virtual async Task<bool> ConsumeMessage(bool redelivered, ulong deliveryTag, IBasicProperties properties, byte[] body)
        {
            DataContractKey dataContractKey = properties.GetDataContractKey();

            var subscription =
                _subscriptions.Where(p => p.Value.FilterInfo.ContractKey.Equals(dataContractKey)).Select(
                    pair =>
                        new
                        {
                            DataType = pair.Key,
                            pair.Value.Handler
                        }).FirstOrDefault();

            if (subscription == null)
            {
                 RawBusMessage rawBusMessage = _messageHelper.ConstructMessage(dataContractKey, properties, (object)body);

                _errorSubscriber.UnregisteredMessageArrived(rawBusMessage);

                return false;
            }

            object data;

            if (!_serializers.ContainsKey(properties.ContentType))
            {
                RawBusMessage rawBusMessage = _messageHelper.ConstructMessage(dataContractKey, properties, (object)body);

                _errorSubscriber.MessageDeserializeException(rawBusMessage, new Exception("Unsupported content type"));

                return false;
            }

            ISerializer serializer;
            
            try
            {
                serializer = _serializers[properties.ContentType];
                
                data = serializer.Deserialize(dataContractKey, subscription.DataType, body);
            }
            catch (Exception ex)
            {
                RawBusMessage rawBusMessage = _messageHelper.ConstructMessage(dataContractKey, properties, (object)body);

                _errorSubscriber.MessageDeserializeException(rawBusMessage, ex);

                return false;
            }
            
            RawBusMessage message = _messageHelper.ConstructMessage(dataContractKey, properties, data);

            if (!_receiveSelfPublish && _busId.Equals(message.BusId))
            {
                _errorSubscriber.MessageFilteredOut(message);

                return false;
            }

            _trace.MessageArrived(_busId, message, ConsumerTag);

            RawBusMessage reply;

            try
            {
                reply = await HandleMessage(subscription.Handler, message, redelivered, deliveryTag);
            }
            catch (RejectMessageException ex)
            {
                reply = new RawBusMessage
                {
                    Data = ex.ReplyData
                };
                
                reply.Headers.Add(new RejectedHeader());
            }
            catch (Exception ex)
            {
                _errorSubscriber.MessageDispatchException(message, ex);

                reply = new RawBusMessage();

                reply.Headers.Add(new ExceptionHeader
                {
                    Message = ex.Message
                });
            }

            if (!_neverReply && reply != null && properties.IsReplyToPresent())
            {
                _sendHelper.Send(new SendParams
                {
                    BusId = _busId,
                    BusMessage = reply,
                    Model = Model,
                    CorrelationId = properties.IsCorrelationIdPresent() ? properties.CorrelationId : "",
                    Exchange = _replyExchange,
                    RoutingKey = properties.ReplyTo,
                    Serializer = serializer,
                    MandatoryDelivery = false,
//.........这里部分代码省略.........
开发者ID:parshim,项目名称:MessageBus,代码行数:101,代码来源:MessageConsumer.cs

示例3: HandleBasicDeliver

        public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body)
        {
            if (!properties.IsCorrelationIdPresent())
            {
                return;
            }

            CallbackInfo info;

            if (_callbacksDictionary.TryRemove(properties.CorrelationId, out info))
            {
                var rejectHeader =
                    properties.Headers.Where(pair => pair.Key == RejectedHeader.WellknownName)
                        .Select(pair => pair.Value)
                        .FirstOrDefault();

                var exceptionHeader =
                    properties.Headers.Where(pair => pair.Key == ExceptionHeader.WellknownName)
                        .Select(pair => pair.Value)
                        .FirstOrDefault();

                if (exceptionHeader != null)
                {
                    info.SetResponse(null, new RpcCallException(RpcFailureReason.HandlerError, exceptionHeader.ToString()));

                    return;
                }

                DataContractKey dataContractKey;
                object data;

                if (body.Length == 0 || info.ReplyType == null)
                {
                    // Reject without data
                    if (rejectHeader != null)
                    {
                        info.SetResponse(null, new RpcCallException(RpcFailureReason.Reject));

                        return;
                    }

                    // Void reply or sender not interested in reply data, but only interested to be notified that work is done
                    dataContractKey = DataContractKey.Void;
                    data = null;
                }
                else
                {
                    dataContractKey = properties.GetDataContractKey();

                    if (!_serializers.ContainsKey(properties.ContentType))
                    {
                        info.SetResponse(null,
                            new RpcCallException(RpcFailureReason.SerializationError,
                                string.Format("Unsupported content type {0}", properties.ContentType)));

                        return;
                    }

                    try
                    {
                        ISerializer serializer = _serializers[properties.ContentType];

                        data = serializer.Deserialize(dataContractKey, info.ReplyType, body);
                    }
                    catch (Exception ex)
                    {
                        info.SetResponse(null, new RpcCallException(RpcFailureReason.SerializationError, ex));

                        return;
                    }
                }

                // Reject with data
                if (rejectHeader != null)
                {
                    info.SetResponse(null, new RpcCallException(RpcFailureReason.Reject, data));

                    return;
                }

                RawBusMessage message = _messageHelper.ConstructMessage(dataContractKey, properties, data);

                _trace.MessageArrived(_busId, message, ConsumerTag);

                info.SetResponse(message, null);

                info.RegisteredHandle.Unregister(info.WaitHandle);
            }
        }
开发者ID:parshim,项目名称:MessageBus,代码行数:89,代码来源:RpcConsumer.cs

示例4: ConsumeMessage

        private void ConsumeMessage(bool redelivered, ulong deliveryTag, IBasicProperties properties, byte[] body)
        {
            DataContractKey dataContractKey = properties.GetDataContractKey();

            var subscription =
                _subscriptions.Where(p => p.Value.FilterInfo.ContractKey.Equals(dataContractKey)).Select(
                    pair =>
                        new
                        {
                            DataType = pair.Key,
                            pair.Value.Handler
                        }).FirstOrDefault();

            if (subscription == null)
            {
                 RawBusMessage rawBusMessage = _messageHelper.ConstructMessage(dataContractKey, properties, (object)body);

                _errorSubscriber.UnregisteredMessageArrived(rawBusMessage);

                return;
            }

            object data;

            if (!_serializers.ContainsKey(properties.ContentType))
            {
                RawBusMessage rawBusMessage = _messageHelper.ConstructMessage(dataContractKey, properties, (object)body);

                _errorSubscriber.MessageDeserializeException(rawBusMessage, new Exception("Unsupported content type"));

                return;
            }

            try
            {
                data = _serializers[properties.ContentType].Deserialize(dataContractKey, subscription.DataType, body);
            }
            catch (Exception ex)
            {
                RawBusMessage rawBusMessage = _messageHelper.ConstructMessage(dataContractKey, properties, (object)body);

                _errorSubscriber.MessageDeserializeException(rawBusMessage, ex);

                return;
            }

            RawBusMessage message = _messageHelper.ConstructMessage(dataContractKey, properties, data);

            if (!_receiveSelfPublish && _busId.Equals(message.BusId))
            {
                _errorSubscriber.MessageFilteredOut(message);

                return;
            }

            try
            {
                HandleMessage(subscription.Handler, message, redelivered, deliveryTag);
            }
            catch (Exception ex)
            {
                _errorSubscriber.MessageDispatchException(message, ex);
            }
        }
开发者ID:ronybot,项目名称:MessageBus,代码行数:64,代码来源:MessageConsumer.cs


注:本文中的IBasicProperties.GetDataContractKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。