private void DoAck(ConsumerExecutionContext context, AckStrategy ackStrategy) { const string failedToAckMessage = "Basic ack failed because channel was closed with message '{0}'." + " Message remains on RabbitMQ and will be retried." + " ConsumerTag: {1}, DeliveryTag: {2}"; var ackResult = AckResult.Exception; var deliverTag = context.Info.DeliverTag; try { ackResult = ackStrategy(context.Consumer.Model, deliverTag); } catch (AlreadyClosedException alreadyClosedException) { Logger.Info(failedToAckMessage, alreadyClosedException.Message, context.Info.ConsumerTag, deliverTag); } catch (IOException ioException) { Logger.Info(failedToAckMessage, ioException.Message, context.Info.ConsumerTag, deliverTag); } catch (Exception exception) { Logger.Error("Unexpected exception when attempting to ACK or NACK\n{0}", exception); } finally { EventBus.Publish(new AckEvent(context.Info, context.Properties, context.Body, ackResult)); } }
/// <summary> /// 发送ack回执 /// </summary> /// <param name="context"></param> /// <param name="ackStrategy"></param> private void DoAck(ConsumerExecutionContext context, AckStrategy ackStrategy) { const string failedToAckMessage = "Basic ack failed because channel was closed with message '{0}'." + " Message remains on RabbitMQ and will be retried." + " ConsumerTag: {1}, DeliveryTag: {2}"; AckResult ackResult = AckResult.Exception; try { Preconditions.CheckNotNull(context.Consumer.Model, "context.Consumer.Model"); ackResult = ackStrategy(context.Consumer.Model, context.Info.DeliverTag); } catch (AlreadyClosedException alreadyClosedException) { ConsoleLogger.InfoWrite(failedToAckMessage, alreadyClosedException.Message, context.Info.ConsumerTag, context.Info.DeliverTag); } catch (IOException ioException) { ConsoleLogger.InfoWrite(failedToAckMessage, ioException.Message, context.Info.ConsumerTag, context.Info.DeliverTag); } catch (Exception exception) { ConsoleLogger.ErrorWrite("Unexpected exception when attempting to ACK or NACK\n{0}", exception); } finally { EventBus.Instance.Publish(new AckEvent(context, ackResult)); } }
public void SetUp() { var customConventions = new Conventions(new TypeNameSerializer()) { ErrorQueueNamingConvention = () => "CustomEasyNetQErrorQueueName", ErrorExchangeNamingConvention = info => "CustomErrorExchangePrefixName." + info.RoutingKey }; mockBuilder = new MockBuilder(); errorStrategy = new DefaultConsumerErrorStrategy( mockBuilder.ConnectionFactory, new JsonSerializer(new TypeNameSerializer()), MockRepository.GenerateStub <IEasyNetQLogger>(), customConventions, new TypeNameSerializer(), new DefaultErrorMessageSerializer()); const string originalMessage = ""; var originalMessageBody = Encoding.UTF8.GetBytes(originalMessage); var context = new ConsumerExecutionContext( (bytes, properties, arg3) => null, new MessageReceivedInfo("consumerTag", 0, false, "orginalExchange", "originalRoutingKey", "queue"), new MessageProperties { CorrelationId = string.Empty, AppId = string.Empty }, originalMessageBody, MockRepository.GenerateStub <IBasicConsumer>() ); try { errorAckStrategy = errorStrategy.HandleConsumerError(context, new Exception()); cancelAckStrategy = errorStrategy.HandleConsumerCancelled(context); } catch (Exception) { // swallow } }
protected virtual void DoAck(ConsumerExecutionContext context, AckStrategy ackStrategy) { var ackResult = AckResult.Exception; try { Preconditions.CheckNotNull(context.Consumer.Model, "context.Consumer.Model"); ackResult = ackStrategy(context.Consumer.Model, context.Info.DeliverTag); } catch (AlreadyClosedException alreadyClosedException) { logger.Info( alreadyClosedException, "Failed to ACK or NACK, message will be retried, receivedInfo={receivedInfo}", context.Info ); } catch (IOException ioException) { logger.Info( ioException, "Failed to ACK or NACK, message will be retried, receivedInfo={receivedInfo}", context.Info ); } catch (Exception exception) { logger.Error( exception, "Unexpected exception when attempting to ACK or NACK, receivedInfo={receivedInfo}", context.Info ); } finally { eventBus.Publish(new AckEvent(context.Info, context.Properties, context.Body, ackResult)); } }
public void SetUp() { var customConventions = new Conventions(new TypeNameSerializer()) { ErrorQueueNamingConvention = () => "CustomEasyNetQErrorQueueName", ErrorExchangeNamingConvention = info => "CustomErrorExchangePrefixName." + info.RoutingKey }; mockBuilder = new MockBuilder(); errorStrategy = new DefaultConsumerErrorStrategy( mockBuilder.ConnectionFactory, new JsonSerializer(new TypeNameSerializer()), MockRepository.GenerateStub<IEasyNetQLogger>(), customConventions, new TypeNameSerializer()); const string originalMessage = ""; var originalMessageBody = Encoding.UTF8.GetBytes(originalMessage); var context = new ConsumerExecutionContext( (bytes, properties, arg3) => null, new MessageReceivedInfo("consumerTag", 0, false, "orginalExchange", "originalRoutingKey", "queue"), new MessageProperties { CorrelationId = string.Empty, AppId = string.Empty }, originalMessageBody, MockRepository.GenerateStub<IBasicConsumer>() ); try { errorAckStrategy = errorStrategy.HandleConsumerError(context, new Exception()); cancelAckStrategy = errorStrategy.HandleConsumerCancelled(context); } catch (Exception) { // swallow } }
private void DoAck(ConsumerExecutionContext context, AckStrategy ackStrategy) { const string failedToAckMessage = "Basic ack failed because channel was closed with message '{0}'." + " Message remains on RabbitMQ and will be retried." + " ConsumerTag: {1}, DeliveryTag: {2}"; var ackResult = AckResult.Exception; try { Preconditions.CheckNotNull(context.Consumer.Model, "context.Consumer.Model"); ackResult = ackStrategy(context.Consumer.Model, context.Info.DeliverTag); } catch (AlreadyClosedException alreadyClosedException) { logger.InfoWrite(failedToAckMessage, alreadyClosedException.Message, context.Info.ConsumerTag, context.Info.DeliverTag); } catch (IOException ioException) { logger.InfoWrite(failedToAckMessage, ioException.Message, context.Info.ConsumerTag, context.Info.DeliverTag); } catch (Exception exception) { logger.ErrorWrite("Unexpected exception when attempting to ACK or NACK\n{0}", exception); } finally { eventBus.Publish(new AckEvent(context.Info, context.Properties, context.Body, ackResult)); } }