Retaining MDC with Spring AMQP Request/Reply

916 views Asked by At

I have two services, A and B, communicating via Spring Remoting with AMQP. A exposes a REST API and populates the MDC (Mapped Diagnostic Context) with a UUID.randomUUID() (from within a Filter) on every request (and clears it when processing is finished). Now I'd like to pass this UUID to B in the request/reply cycle so that...

  1. ... when a consumer in B starts processing the request, its MDC is populated with the UUID.
  2. ... when the consumer in B finishes processing the request, its MDC is cleared.

I've extended SimpleMessageConverter so as to set an AMQP header containing the UUID, but I don't really seem to figure out how/where to populate and how/where to clear the MDC in B. Can anyone please shed some light?

1

There are 1 answers

2
Gary Russell On BEST ANSWER

Inject another custom message converter into the AmqpInvokerServiceExporter.

Set the MDC (from the header) in fromMessage(), clear it when the reply is mapped (in toMessage).