Search code examples
spring-rabbitmdc

Set MDC properties only for rabbitmq events


I want to apply filters to log only for rabbit events using MDC properties. And set trace Id && correlation id from the event header.

I already have a RequestResponseLoggingFilter which is used for setting the tenant Id.

I am not sure how to trigger this filter only for async rabbit events.


Solution

  • If you are using a MessageListener or @RabbitListener you can add a MessagePostProcessor to the listener container (or listener container factory, respectively) in the afterReceivePostProcessors property.

    The post processor(s) are called after a message is received and before the listener is called.