本文整理汇总了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();
}