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


C# Envelope.SetReceiptTime方法代码示例

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


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

示例1: Start

        public void Start()
        {
            _log.Debug("Enter Start");
            _shouldContinue = true;

            using (IModel channel = _connection.CreateModel())
            {
                // first, declare the exchange and queue
                channel.ExchangeDeclare(_exchange.Name, _exchange.ExchangeType, _exchange.IsDurable, _exchange.IsAutoDelete, _exchange.Arguments);
                channel.QueueDeclare(_exchange.QueueName, _exchange.IsDurable, false, _exchange.IsAutoDelete, _exchange.Arguments);
                channel.QueueBind(_exchange.QueueName, _exchange.Name, _exchange.RoutingKey, _exchange.Arguments);

                // next, create a basic consumer
                QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);

                // and tell it to start consuming messages, storing the consumer tag
                string consumerTag = channel.BasicConsume(_exchange.QueueName, false, consumer);

                _log.Debug("Will now continuously listen for events using routing key: " + _exchange.RoutingKey);
                while (_shouldContinue)
                {
                    try
                    {
                        object result = null;

                        if (false == consumer.Queue.Dequeue(100, out result)) { continue; }
                        BasicDeliverEventArgs e = result as BasicDeliverEventArgs;
                        if (null == e) { continue; }
                        else { this.LogMessage(e); }

                        IBasicProperties props = e.BasicProperties;

                        Envelope env = new Envelope();
                        env.SetReceiptTime(DateTime.Now);
                        env.Payload = e.Body;
                        foreach (DictionaryEntry entry in props.Headers)
                        {
                            try
                            {
                                string key = entry.Key as string;
                                string value = Encoding.UTF8.GetString((byte[])entry.Value);
                                _log.Debug("Adding header to envelope: {" + key + ":" + value + "}");

                                env.Headers.Add(key, value);
                            }
                            catch { }
                        }

                        if (this.ShouldRaiseEvent(_registration.Filter, env))
                        {
                            RabbitEnvelopeDispatcher dispatcher = new RabbitEnvelopeDispatcher(_registration, env, channel, e.DeliveryTag);
                            this.Raise_OnEnvelopeReceivedEvent(dispatcher);
                        }
                    }
                    catch (OperationInterruptedException)
                    {
                        // The consumer was removed, either through
                        // channel or connection closure, or through the
                        // action of IModel.BasicCancel().
                        _shouldContinue = false;
                    }
                    catch { }
                }
                _log.Debug("No longer listening for events");

                try { channel.BasicCancel(consumerTag); }
                catch (OperationInterruptedException) { }
            }

            _log.Debug("Leave Start");
        }
开发者ID:berico-tpinney,项目名称:AMP,代码行数:71,代码来源:RabbitListener.cs


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