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