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


C# IMessageHandler.BeforeHandlingMessage方法代码示例

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


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

示例1: BurrowConsumer

        public BurrowConsumer(IModel channel,
                              IMessageHandler messageHandler,
                              IRabbitWatcher watcher,                     
                              
                              bool autoAck,
                              int batchSize)
            : base(channel, new SharedQueue())
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }
            if (messageHandler == null)
            {
                throw new ArgumentNullException("messageHandler");
            }
            if (watcher == null)
            {
                throw new ArgumentNullException("watcher");
            }
            
            if (batchSize < 1)
            {
                throw new ArgumentNullException("batchSize", "batchSize must be greater than or equal 1");
            }

            Model.ModelShutdown += WhenChannelShutdown;
            Model.BasicRecoverAsync(true);
            BatchSize = batchSize;

            _pool = new Semaphore(BatchSize, BatchSize);
            _watcher = watcher;
            _autoAck = autoAck;


            _messageHandler = messageHandler;
            _messageHandler.HandlingComplete += MessageHandlerHandlingComplete;
            _subscriptionCallbackThread = new Thread(_ =>
            {
                Thread.CurrentThread.Name = string.Format("Consumer thread: {0}", ConsumerTag);
                while (!_disposed)
                {
                    try
                    {
                        BasicDeliverEventArgs deliverEventArgs;
                        lock (_sharedQueueLock)
                        {
                            _pool.WaitOne();
                            deliverEventArgs = (BasicDeliverEventArgs) Queue.Dequeue();
                        }
                        if (deliverEventArgs != null)
                        {
                            _messageHandler.BeforeHandlingMessage(this, deliverEventArgs);
                            HandleMessageDelivery(deliverEventArgs);
                        }
                    }
                    catch(ThreadAbortException)
                    {
                        _watcher.WarnFormat("The consumer thread {0} is aborted", ConsumerTag);
                    }
                    catch (EndOfStreamException)
                    {
                        // do nothing here, EOS fired when queue is closed
                        // Looks like the connection has gone away, so wait a little while
                        // before continuing to poll the queue
                        Thread.Sleep(10);
                    }
                }
            });
            _subscriptionCallbackThread.Start();
        }
开发者ID:brett--anderson,项目名称:Burrow.NET,代码行数:71,代码来源:BurrowConsumer.cs


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