本文整理汇总了C#中IModel.BasicReject方法的典型用法代码示例。如果您正苦于以下问题:C# IModel.BasicReject方法的具体用法?C# IModel.BasicReject怎么用?C# IModel.BasicReject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IModel
的用法示例。
在下文中一共展示了IModel.BasicReject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public void Process(
IModel channel,
BasicDeliverEventArgs message)
{
var _logMessageContext = string.Format("type header = {0}, message Id = {1}, correlation Id = {2} and delivery tag = {3}",
message.BasicProperties.Type,
message.BasicProperties.MessageId,
message.BasicProperties.CorrelationId,
message.DeliveryTag);
this.c_logger.DebugFormat("Process About to handle message, {0}", _logMessageContext);
if (!this.c_configuration.MessageConsumers.HasConfiguration(message.BasicProperties.Type))
{
this.c_logger.DebugFormat("Process No match found for message, {0}", _logMessageContext);
//pending - see errored below
channel.BasicNack(message.DeliveryTag, false, false);
return;
}
var _configuration = this.c_configuration.MessageConsumers[message.BasicProperties.Type];
var _actionResult = ConsumerHandlerResult.None;
try
{
this.c_logger.DebugFormat("Process About to deserialze message for message, {0}", _logMessageContext);
var _messageJson = Encoding.UTF8.GetString(message.Body);
var _message = JsonConvert.DeserializeObject(_messageJson, _configuration.Type);
this.c_logger.DebugFormat("Process About to invoke action for message, {0}", _logMessageContext);
_actionResult = _configuration.Action(_message as Message);
}
catch (Exception exception)
{
this.c_logger.WarnFormat("Process Encountered error for message {0} Error: {1}", _logMessageContext, exception.InstrumentationString());
_actionResult = ConsumerHandlerResult.Errored;
}
this.c_logger.DebugFormat("Process Completed processing for message, {0}, result is {1}", _logMessageContext, _actionResult);
if (_actionResult == ConsumerHandlerResult.Errored)
{
//pending - should i use configuration properties
// Nack, do not requeue, dead letter the message if dead letter exchange configured for the queue
channel.BasicNack(message.DeliveryTag, false, false);
}
else if (_actionResult == ConsumerHandlerResult.Completed)
{
channel.BasicAck(message.DeliveryTag, false);
}
else if (_actionResult == ConsumerHandlerResult.Requeue)
{
//pending does this make sense ?
channel.BasicReject(message.DeliveryTag, true);
}
this.c_logger.DebugFormat("Process Completed handling message, {0}, Result is {1}", _logMessageContext, _actionResult);
}
示例2: AckOrReject
private static void AckOrReject(IModel channel, ulong deliveryTag, string message)
{
if (message.Contains("WTF"))
{
Console.WriteLine("REJECTED: {0}", message);
channel.BasicReject(deliveryTag, false);
}
else
{
Console.WriteLine("Received: {0}", message);
channel.BasicAck(deliveryTag, false);
}
}