Is there a hook to add a header to every message sent using JmsTemplate?

Viewed 14

Is there a hook to add a header to every message sent using JmsTemplate?

We are building a system where a tracing ID is passed from system to system and used in the logs so we can trace requests across system. The tracing ID is stored in the logging frameworks Mapped Diagnostic Context (MDC) whenever an HTTP request or JMS Message is received and then removed when the processing is completed for that request.

For HTTP requests we send, we are using Apache HTTP Client and using a HttpRequestInterceptor to add put the current request ID into a header named "request_tracing_id". In the business logic the developer doesn't need to worry about adding the tracing ID to outgoing requests because we used a pre-configured HTTP Client with the before mentioned HttpRequestInterceptor.

Does Spring's JmsTemplate have a similar feature were we can have some header added to every outgoing message? Right now we are calling setStringProperty(...) in nearly every place we send a message. Sadly, the phrase "nearly every place" is correct. I'd like to, if possible, keep using Spring's JmsTemplate to send the messages, but have a plugin to JmsTemplate to add the tracing ID automatically so we can quit doing it manually.

Is this possible? I can't find a spot to put this logic that applies to the use of all "send(...)" and createAndSend(...) calls. Did I miss it?

We'd also like to automatically set the reply-queue name to a server-specific queue since we are doing an old-school request-reply JMS integration where the requestor specifies a queue to send the reply back to. Fortunately, the code doesn't work at all if the reply queue is missing so the reply queue name always gets set. It would be nice to eliminate this boilerplate though....

0 Answers
Related