1

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?

Roy Stark
  • 463
  • 2
  • 15

1 Answers1

0

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

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • After some research I found that I can inject a `MethodInterceptor` with `#SimpleMessageListenerContainer.setAdviceChain` which basically does the thing. Which of the two approaches do you think is preferable? – Roy Stark Jun 23 '15 at 18:45
  • Yes, that will work too. Since you need a custom converter on the sending side, it seems more symmetrical to me to use a converter on the receiving side too. It might be easier for other developers (who might come to your project later) to understand too. But, functionally, there's not really any difference so I don't really have an ax to grind either way. – Gary Russell Jun 23 '15 at 20:05