如何在两个队列之间关联 Websphere MQ 的请求和响应

how to correlate request and reponse of Websphere MQ between two queues

  1. Q1 上请求和响应消息的相关性,即如果 Q1 向 Q2 发送 100 条消息并收到 100 条消息,Q1 应该能够将这 100 条响应与请求相关联。这是为了确保将响应绑定回正确的请求,并将正确的响应发送回调用应用程序。我们正在使用 GUID 作为相关 ID。
  2. 将超时 属性 设置为 50 秒。这是为了实现如果响应在 50 秒内返回,则将响应发送回调用应用程序。如果响应在 50 秒后返回,则将超时响应发送到调用应用程序。

我需要对其进行 POC,请帮助..

  • Req/Resp 匹配:如果您的 GUID 对于每条消息都是唯一的,那么您可以使用它来关联请求和响应消息。另一种选择是从请求中获取消息 ID,然后在响应消息中设置为关联 ID。

更多详情请点击这里:

IBM WebSphere MQ request/reply scenario

样本:https://www.ibm.com/developerworks/community/blogs/messaging/entry/jms_request_reply_sample?lang=en

  • 超时时间:可以在JMS的receive方法中指定超时时间。该示例涵盖了这一点。如果您想使用 C 应用程序,可以在 MQGET 调用中使用选项(MQGMO_WAIT with Wait Interval.)

我能够使用 Spring DSL 关联请求响应场景。在骆驼的帮助下,它很容易。

 <route id="request12">
        <from uri="WebsphereMq:queue:Queue1"/>

        <to uri="bean:mycode"/>
        <process ref="msgProcessor"/>

        <to uri="WebsphereMq:queue:Queue2 requestTimeout=50s" pattern="InOut"/>

        <onException>

    <exception>
         org.apache.camel.ExchangeTimedOutException
    </exception>

        <transform>
             <simple>Exachange Timeout Error</simple>
                      </transform>
                     <to uri="seda:response"/>
                </onException>
            <to uri="seda:response"/> 

        </route> 

<route id="Response">
            <from uri="seda:response" />

           <to uri="WebsphereMq:queue:ResponseQ"/>

        </route>