Patrik Mihalčin
Patrik Mihalčin

Reputation: 3991

Log XML payload when MarshallingMessageConverter is used in Spring Integration's Amqp inboundAdapter

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?

Upvotes: 0

Views: 210

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121272

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().

Upvotes: 2

Related Questions