I have IntegrationFlow
which listens for AMQP messages and I want to log XML message payload.
IntegrationFlows.from(
Amqp.inboundAdapter(rabbitConnectionFactory, QUEUE)
.messageConverter(new MarshallingMessageConverter(xmlMarshaller))
)
.log(INFO, "org.springframework.amqp")
...
.get();
When I use MarshallingMessageConverter
in Amqp.inboundAdapter()
, then already deserialized object instead of XML payload is logged in .log()
step
I can get around this problem with default SimpleMessageConverter
and explicit .transform()
step.
Is there a way how to log original XML payload and keep using MarshallingMessageConverter
?
One of the way is to add a MessagePostProcessor
into a listener container:
Amqp.inboundAdapter(rabbitConnectionFactory, QUEUE)
.messageConverter(new MarshallingMessageConverter(xmlMarshaller))
.configureContainer(container ->
container.afterReceivePostProcessors(message ->
logger.info(new String(message.getBody()))))
Another one, of course, is to extend that MarshallingMessageConverter
and override its fromMessage(Message message)
to log the body before calling super.fromMessage()
.