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


C# IModel.BasicNack方法代码示例

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


在下文中一共展示了IModel.BasicNack方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: RollbackOnExceptionIfNecessary

        /// <summary>
        /// Perform a rollback, handling rollback excepitons properly.
        /// </summary>
        /// <param name="channel">
        /// The channel to rollback.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="ex">
        /// The thrown application exception.
        /// </param>
        protected virtual void RollbackOnExceptionIfNecessary(IModel channel, Message message, Exception ex)
        {
            var ackRequired = !this.AcknowledgeMode.IsAutoAck() && !this.AcknowledgeMode.IsManual();
            try
            {
                if (this.IsChannelTransacted)
                {
                    if (this.logger.IsDebugEnabled)
                    {
                        this.logger.Debug("Initiating transaction rollback on application exception" + ex);
                    }

                    RabbitUtils.RollbackIfNecessary(channel);
                }

                if (message != null)
                {
                    if (ackRequired)
                    {
                        if (this.logger.IsDebugEnabled)
                        {
                            this.logger.Debug("Rejecting message");
                        }

                        // channel.BasicReject((ulong)message.MessageProperties.DeliveryTag, true);
                        channel.BasicNack((ulong)message.MessageProperties.DeliveryTag, true, true);
                    }

                    if (this.IsChannelTransacted)
                    {
                        // Need to commit the reject (=nack)
                        RabbitUtils.CommitIfNecessary(channel);
                    }
                }
            }
            catch (Exception e)
            {
                this.logger.Error("Application exception overriden by rollback exception", ex);
                throw;
            }
        }
开发者ID:DonMcRae,项目名称:spring-net-amqp,代码行数:53,代码来源:AbstractMessageListenerContainer.cs

示例3: ExceptionAckStrategy

 private AckResult ExceptionAckStrategy(IModel model, ulong deliveryTag, PostExceptionAckStrategy strategy)
 {
     switch (strategy)
     {
         case PostExceptionAckStrategy.ShouldAck:
             model.BasicAck(deliveryTag, false);
             return AckResult.Ack;
         case PostExceptionAckStrategy.ShouldNackWithoutRequeue:
             model.BasicNack(deliveryTag, false, false);
             return AckResult.Nack;
         case PostExceptionAckStrategy.ShouldNackWithRequeue:
             model.BasicNack(deliveryTag, false, true);
             return AckResult.Nack;
         case PostExceptionAckStrategy.DoNothing:
             return AckResult.Nothing;
         default:
             return AckResult.Nothing;
     }
 }
开发者ID:jonstelly,项目名称:EasyNetQ,代码行数:19,代码来源:HandlerRunner.cs

示例4: HandleDelivery

        private void HandleDelivery(IModel channel, BasicDeliverEventArgs delivery, CancellationToken cancellationToken)
        {
            try
            {
                // Put on the thread pool to avoid deadlock
                var acknowleged = Task.Run(() => DispatchToListener(delivery, cancellationToken),
                    cancellationToken).Result;

                if (acknowleged)
                {
                    Log.DebugFormat(
                        "Acknowledging message {0} from RabbitMQ queue \"{1}\" on channel {2}...",
                        delivery.DeliveryTag, _queueName, channel.ChannelNumber);

                    channel.BasicAck(delivery.DeliveryTag, false);
                }
                else
                {
                    Log.DebugFormat(
                        "Message {0} from RabbitMQ queue \"{1}\" received on channel {2} not acknowledged",
                        delivery.DeliveryTag, _queueName, channel.ChannelNumber);

                    // Add 1 to the header value because the number of attempts will be zero
                    // on the first try
                    var currentAttempt = delivery.BasicProperties.GetDeliveryAttempts() + 1;
                    if (currentAttempt < _maxAttempts)
                    {
                        Log.DebugFormat(
                            "Re-publishing message {0} to retry queue \"{1}\" for redelivery...",
                            delivery.DeliveryTag, _retryQueueName);

                        var retryProperties = delivery.BasicProperties;
                        retryProperties.IncrementDeliveryAttempts();
                        channel.BasicPublish(_retryExchange, "", retryProperties, delivery.Body);
                    }
                    else
                    {
                        Log.WarnFormat(
                            "Maximum delivery attempts for message {0} exceeded.  Sending NACK on channel {1}...",
                            delivery.DeliveryTag, channel.ChannelNumber);

                        channel.BasicNack(delivery.DeliveryTag, false, false);
                    }
                }
            }
            catch (Exception e)
            {
                Log.ErrorFormat("Error processing message {0} from RabbitMQ queue \"{1}\" on channel {2}", e,
                    delivery.DeliveryTag, _queueName, channel.ChannelNumber);

                // Due to the complexity of managing retry counts and delays in
                // RabbitMQ, retries are handled in the HandleDelivery method.
                // Therefore if we get to this point, we've done the best we
                // could.
                channel.BasicNack(delivery.DeliveryTag, false, false);
            }
        }
开发者ID:tdbrian,项目名称:Platibus,代码行数:57,代码来源:RabbitMQQueue.cs

示例5: ExceptionAckStrategy

 private void ExceptionAckStrategy(IModel model, ulong deliveryTag)
 {
     switch (consumerErrorStrategy.PostExceptionAckStrategy())
     {
         case PostExceptionAckStrategy.ShouldAck:
             model.BasicAck(deliveryTag, false);
             break;
         case PostExceptionAckStrategy.ShouldNackWithoutRequeue:
             model.BasicNack(deliveryTag, false, false);
             break;
         case PostExceptionAckStrategy.ShouldNackWithRequeue:
             model.BasicNack(deliveryTag, false, true);
             break;
         case PostExceptionAckStrategy.DoNothing:
             break;
     }
 }
开发者ID:siniypin,项目名称:EasyNetQ,代码行数:17,代码来源:HandlerRunner.cs

示例6: ContinueReceiving

        private void ContinueReceiving(QueueingBasicConsumer consumer, Guid channelId, IModel channel)
        {
            try
            {
                while (IsReceiving)
                {
                    var ea = consumer.Queue.Dequeue();
                    var body = ea.Body;
                    var message = _encode.GetString(body);

                    Logger.Debug("[{0}]�ѽ��յ���Ϣ��{1}", channelId, message);

                    var success = HandleMessage(message);

                    if (success)
                    {
                        Logger.Debug("[{0}]����ɹ����ѷ��ͻ�ִ��Ϣ(Ack)��", channelId);

                        channel.BasicAck(ea.DeliveryTag, false);
                    }
                    else
                    {
                        Logger.Debug("[{0}]����ʧ�ܣ��ѷ��ͻ�ִ��Ϣ(Nack)��׼�����½��ܴ�����Ϣ��", channelId);

                        channel.BasicNack(ea.DeliveryTag, false, true);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new MqException("ִ�н�����Ϣʧ�ܡ�", ex);
            }
        }
开发者ID:IcyExile,项目名称:CRQ,代码行数:34,代码来源:MessageReceiver.cs

示例7: TryAckOrNack

        internal static void TryAckOrNack(string consumerTag, bool ack, IModel channel, ulong deliveryTag, bool multiple, bool requeue, IRabbitWatcher watcher = null)
        {
            try
            {
                if (channel == null)
                {
                    (watcher ?? Global.DefaultWatcher).WarnFormat("Trying ack/nack msg but the Channel is null, will not do anything");
                }
                else if (!channel.IsOpen)
                {
                    (watcher ?? Global.DefaultWatcher).WarnFormat("Trying ack/nack msg but the Channel is not open, will not do anything");
                }
                else
                {
                    if (ack)
                    {
                        channel.BasicAck(deliveryTag, multiple);
                    }
                    else
                    {
                        channel.BasicNack(deliveryTag, multiple, requeue);
                    }

                    lock (OutstandingDeliveryTags)
                    {
                        if (OutstandingDeliveryTags.ContainsKey(consumerTag))
                        {
                            if (deliveryTag == 0)
                            {
                                // Ack/Nack all out standing
                                OutstandingDeliveryTags[consumerTag].Clear();
                            }
                            else if (multiple)
                            {
                                // Ack/Nack all up to
                                OutstandingDeliveryTags[consumerTag].RemoveAll(x => x <= deliveryTag);
                                //(watcher ?? Global.DefaultWatcher).InfoFormat("Ack/Nack multiple tags <= {0} for consumer {1}", deliveryTag, consumerTag);
                                //(watcher ?? Global.DefaultWatcher).InfoFormat("Outstanding tags {0}", String.Join(",", OutstandingDeliveryTags[consumerTag].OrderBy(x => x)));
                            }
                            else
                            {
                                // Ack/Nack only 1 single tagtag
                                OutstandingDeliveryTags[consumerTag].Remove(deliveryTag);
                            }
                        }
                    }
                }
            }
            catch (AlreadyClosedException alreadyClosedException)
            {
                (watcher ?? Global.DefaultWatcher).WarnFormat(FailedToAckMessage, alreadyClosedException.Message);
            }
            catch (IOException ioException)
            {
                (watcher ?? Global.DefaultWatcher).WarnFormat(FailedToAckMessage, ioException.Message);
            }
        }
开发者ID:kangkot,项目名称:Burrow.NET,代码行数:57,代码来源:Subscription.cs

示例8: HandleMessage

		async void HandleMessage(Subscription s, byte[] data, ulong tag, IModel model)
		{
			var status = false;
			try
			{
				await s.Handler(data);
				status = true;
			}
			catch (Exception e)
			{
				_logger("Exception while executing message handler", e);
			}
			SafeExec(_queue.EnqueueTask(m =>
			{
				if (m != model) //Reconnect occured, its not the same connection anymore
					return;
				if (status)
					model.BasicAck(tag, false);
				else
					model.BasicNack(tag, false, true);
			}));


		}
开发者ID:kekekeks,项目名称:distributed-task-queue,代码行数:24,代码来源:RmqSubscriptionManager.cs


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