如何拦截jms入站网关的回复消息

How to intercept the reply message of an jms inbound gateway

我有一个 jms-inbound-gateway 可以读取来自 WebsphereMQ 代理的请求,通过我的集成系统传递它们,然后用响应消息回复。

我需要记录设置了 jms_messageId 和 jms_correlationId header 的消息,这样我就可以匹配日志文件中的 request/reply 消息(并显示它当我的客户说我的回复不正确时给我的客户 jms_correlationId)

设置correlationId header后,有没有办法拦截方法producer.sendReply(...)?

那里不需要拦截; headers 在到达网关之前在网关回复消息中的 Spring 集成消息中可用。

只需将 reply-channel 设为 publish-subscribe-channel 并添加一个将其作为输入通道的 <logging-channel-adapter/>

回复消息将发送到网关和记录器。

如果您使用默认机制来路由回复(在您的最后一个集成组件上没有 output-channel),只需添加一个 output-channel 并路由到回复渠道。

这是在加里输入后我的解决方案的要点:

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