Issue in Correlating request message to resp message in Java Client to access MQ Series

柔情痞子 提交于 2019-12-11 07:17:42

问题


I have used wmqjava sample program to connect to MQ manager and put message in REQUEST queue and get response from RESPONSE queue.

I can put and get the messages. I couldn't get the correct message when there is muliple messages arrived in RESPONSE QUEUE.

Please advice whether there is a way to correlate request and response in this approach.

Please also advice whether this approach is recommended one.


回答1:


Correlation id is the best way to correlate request and response messages. You will need to do the following:

At the requester end:
1) Cache the message id of the request message after the request message is sent.
2) While getting the message specify MQMO_MATCH_CORREL_ID in MQGetMessageOptions.matchOptions field and specify the above message id as the matching value.

At the responder end:
1) Retrieve the message id from the request message.
2) While sending the response message, set the Correlation Id of the response message with message id of request message.

This is how you can correlate request and response messages. Little snippet for requester.

        // Send request message
        MQMessage requestMessage = new MQMessage();
        requestMessage.writeUTF("Request Message");
        reqQueue.put(requestMessage);

        // Receive response
        MQMessage responseMessage = new MQMessage();
        responseMessage.correlationId = requestMessage.messageId;
        MQGetMessageOptions gmo = new MQGetMessageOptions();
        gmo.matchOptions = CMQC.MQMO_MATCH_CORREL_ID;

        respQueue.get(responseMessage,gmo);


来源:https://stackoverflow.com/questions/14607195/issue-in-correlating-request-message-to-resp-message-in-java-client-to-access-mq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!