在 Spring Integration 的 Amqp inboundAdapter 中使用 MarshallingMessageConverter 时记录 XML 负载

问题描述

我有 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() 之前记录正文。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...