Inbound Message Conversion

到达通道适配器或网关的传入消息,将使用消息转换器转换为 spring-messaging Message<?> 有效负载。默认情况下,将使用处理 Java 序列化和文本的 SimpleMessageConverter。默认情况下,会使用 DefaultHeaderMapper.inboundMapper() 映射标头。如果发生转换错误,并且没有定义错误通道,则将向容器抛出异常,并由侦听器容器的错误处理程序处理。默认错误处理程序将转换错误视为致命错误,并且该消息将被拒绝(并且路由到死信交换,如果对队列进行了此配置)。如果定义了错误通道,则 ErrorMessage 有效负载是 ListenerExecutionFailedException,其中包含属性 failedMessage(无法转换的 Spring AMQP 消息)和 cause。如果容器 AcknowledgeModeAUTO(默认),并且错误流程在不抛出异常的情况下使用了该错误,则将确认原始消息。如果有错误流程抛出异常,则异常类型将与容器的错误处理程序结合使用,以确定是否重新排队该消息。如果使用 AcknowledgeMode.MANUAL 配置容器,则有效载荷是 ManualAckListenerExecutionFailedException,其中包含其他属性 channeldeliveryTag。这允许错误流程对该消息调用 basicAckbasicNack(或 basicReject),以控制其处理方式。

Inbound messages, arriving at the channel adapter or gateway, are converted to the spring-messaging Message<?> payload using a message converter. By default, a SimpleMessageConverter is used, which handles java serialization and text. Headers are mapped using the DefaultHeaderMapper.inboundMapper() by default. If a conversion error occurs, and there is no error channel defined, the exception is thrown to the container and handled by the listener container’s error handler. The default error handler treats conversion errors as fatal and the message will be rejected (and routed to a dead-letter exchange, if the queue is so configured). If an error channel is defined, the ErrorMessage payload is a ListenerExecutionFailedException with properties failedMessage (the Spring AMQP message that could not be converted) and the cause. If the container AcknowledgeMode is AUTO (the default) and the error flow consumes the error without throwing an exception, the original message will be acknowledged. If the error flow throws an exception, the exception type, in conjunction with the container’s error handler, will determine whether the message is requeued. If the container is configured with AcknowledgeMode.MANUAL, the payload is a ManualAckListenerExecutionFailedException with additional properties channel and deliveryTag. This enables the error flow to call basicAck or basicNack (or basicReject) for the message, to control its disposition.