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


C# IModel.BasicReject方法代码示例

本文整理汇总了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);
		}
开发者ID:pmcgrath,项目名称:PMCG.Messaging,代码行数:55,代码来源:ConsumerMessageProcessor.cs

示例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);
     }
 }
开发者ID:lukasz-lysik,项目名称:rabbitmq-brown-bag,代码行数:13,代码来源:Program.cs


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