Error Channels

从 1.3 版本开始,binder 无条件地将异常发送给每个消费者目的地的错误频道,也可以配置为将 Async producer 发送失败发送到错误频道。有关更多信息,请参见 “Error Handling”。

Starting with version 1.3, the binder unconditionally sends exceptions to an error channel for each consumer destination and can also be configured to send async producer send failures to an error channel. See “Error Handling” for more information.

RabbitMQ 有两种发送失败类型:

RabbitMQ has two types of send failures:

后者很少见。根据 RabbitMQ 文档,“[Nack] 仅在队列负责的 Erlang 进程中发生内部错误时才传递”。如果发布到具有 `reject-publish`队列溢出行为的有界队列,您也可以得到否定确认。

The latter is rare. According to the RabbitMQ documentation "[A nack] will only be delivered if an internal error occurs in the Erlang process responsible for a queue.". You can also get a negative acknowledgment if you publish to a bounded queue with reject-publish queue overflow behavior.

除了启用生产者错误通道(如 “Error Handling” 所述),RabbitMQ binder 仅在连接工厂适当配置时才将消息发送到频道,如下所示:

As well as enabling producer error channels (as described in “Error Handling”), the RabbitMQ binder only sends messages to the channels if the connection factory is appropriately configured, as follows:

  • ccf.setPublisherConfirms(true);

  • ccf.setPublisherReturns(true);

对连接工厂使用 Spring Boot 配置时,设置以下属性:

When using Spring Boot configuration for the connection factory, set the following properties:

  • spring.rabbitmq.publisher-confirms

  • spring.rabbitmq.publisher-returns

返回的消息的 ErrorMessage 有效负载是一个具有以下属性的 ReturnedAmqpMessageException

The payload of the ErrorMessage for a returned message is a ReturnedAmqpMessageException with the following properties:

  • failedMessage: The spring-messaging Message<?> that failed to be sent.

  • amqpMessage: The raw spring-amqp Message.

  • replyCode: An integer value indicating the reason for the failure (for example, 312 - No route).

  • replyText: A text value indicating the reason for the failure (for example, NO_ROUTE).

  • exchange: The exchange to which the message was published.

  • routingKey: The routing key used when the message was published.

另请参见 Publisher Confirms 以了解接收返回消息的替代机制。

Also see Publisher Confirms for an alternative mechanism to receive returned messages.

对于负确认确认,有效负载是一个具有以下属性的 NackedAmqpMessageException

For negatively acknowledged confirmations, the payload is a NackedAmqpMessageException with the following properties:

  • failedMessage: The spring-messaging Message<?> that failed to be sent.

  • nackReason: A reason (if available — you may need to examine the broker logs for more information).

没有自动处理这些异常(例如发送到 dead-letter queue)。您可以使用自己的 Spring 集成流来处理这些异常。

There is no automatic handling of these exceptions (such as sending to a dead-letter queue). You can consume these exceptions with your own Spring Integration flow.