问题描述
我有 IntegrationFlow
监听 AMQP 消息,我想记录 XML 消息负载。
IntegrationFlows.from(
Amqp.inboundAdapter(rabbitConnectionFactory,QUEUE)
.messageConverter(new MarshallingMessageConverter(xmlMarshaller))
)
.log(INFO,"org.springframework.amqp")
...
.get();
当我在 MarshallingMessageConverter
中使用 Amqp.inboundAdapter()
时,在 .log()
步骤中记录的是已经反序列化的对象而不是 XML 负载
我可以通过默认 SimpleMessageConverter
和显式 .transform()
步骤解决这个问题。
有没有办法记录原始 XML 负载并继续使用 MarshallingMessageConverter
?
解决方法
其中一种方法是将 MessagePostProcessor
添加到侦听器容器中:
Amqp.inboundAdapter(rabbitConnectionFactory,QUEUE)
.messageConverter(new MarshallingMessageConverter(xmlMarshaller))
.configureContainer(container ->
container.afterReceivePostProcessors(message ->
logger.info(new String(message.getBody()))))
当然,另一个是扩展 MarshallingMessageConverter
并覆盖其 fromMessage(Message message)
以在调用 super.fromMessage()
之前记录正文。