2

I have a jms-inbound-gateway that reads requests from a WebsphereMQ broker, passes them though my integration system and then replies with a response message.

I need to log the messages with the jms_messageId and jms_correlationId headers set, so I can match request/reply messages in the log file (and show it to my client when he says that my response does not have the correct jms_correlationId)

Is there a way to intercept the method producer.sendReply(...) after the correlationId header is set?

Martins
  • 1,231
  • 2
  • 14
  • 17

2 Answers2

2

There is no need to intercept there; the headers are available in the Spring Integration messsage in the gateway reply message before it gets to the gateway.

Simply make the reply-channel a publish-subscribe-channel and add a <logging-channel-adapter/> that has it as its input channel.

The reply message will be sent to both the gateway and the logger.

If you are using the default mechanism to route the reply (no output-channel on your last integration component), simply add an output-channel and route to the reply channel.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • You're a genius! Worked like a charm (took me a while because I didn't know about the `reply-channel` attribute). Thank you Gary – Martins Feb 26 '15 at 17:17
1

This is the gist of my solution after Gary's input:

<jms:inbound-gateway 
    id="inboundDestination" 
    connection-factory="connectionFactory"  
    request-destination="nmRequestsQueue" 
    request-channel="request-begin" 
    reply-channel="request-end" 
    error-channel="normaErrorChannel" 
    concurrent-consumers="1" 
    acknowledge="transacted" />

<int:logging-channel-adapter id="request-response-logger"
        log-full-message="true"
        level="DEBUG" 
        logger-name="com.audaxys.si.messages" />

<int:channel id="request-begin">
    <int:interceptors>
        <int:wire-tap channel="request-response-logger" />
    </int:interceptors>
</int:channel>

<int:chain input-channel="request-begin" output-channel="request-end">
    ... Do Stuff ...
</int:chain>

<int:publish-subscribe-channel id="request-end">
    <int:interceptors>
        <int:wire-tap channel="request-response-logger" />
    </int:interceptors>
</int:publish-subscribe-channel>
Martins
  • 1,231
  • 2
  • 14
  • 17
  • For the record; since you're using a wire tap to log, `request-end` doesn't have to be a pub-sub; it would need to be a pub-sub if the logger has `request-end` as its input channel. – Gary Russell Feb 26 '15 at 17:51