Author |
Message
|
rahul13.p |
Posted: Mon Dec 23, 2013 8:00 am Post subject: Note getting response of correlated request |
|
|
Newbie
Joined: 23 Dec 2013 Posts: 4
|
Hi All
I am using MQ for synchronous communication with external application.I have written below code for same but I am not getting the response based on the correlation id or message id of request that I am putting in queue.
Appreciate your valuable inputs as I am struggling with this issue since many days.
Code: |
MQEnvironment.hostname="<host ip>";
MQEnvironment.channel="<MQ environment>";
MQEnvironment.port=MQ port
try{
MQQueueManager qMgr= new MQQueueManager(queue manager name);
MQQueue inputQueue = qMgr.accessQueue("request queue name",MQC.MQOO_OUTPUT);
MQMessage sampleRequest = new MQMessage();
sampleRequest.writeString(sampleXmlRequest);
MQPutMessageOptions pmo = new MQPutMessageOptions();
sampleRequest.replyToQueueManagerName=Queue manager name;
sampleRequest.replyToQueueName="response queue name";
inputQueue.put(sampleRequest, pmo);
MQMessage sampleResponse = new MQMessage();
sampleResponse.correlationId=sampleRequest.correlationId;
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.matchOptions=MQC.MQMO_MATCH_CORREL_ID;
gmo.waitInterval=7000;
gmo.options=MQC.MQGMO_WAIT;
MQQueue outputQueue = qMgr.accessQueue("response queue name", MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT);
outputQueue.get(sampleResponse, gmo);
String msgtext = sampleResponse.readStringOfCharLength(sampleResponse.getMessageLength());
outputQueue.close(); |
|
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Dec 23, 2013 5:21 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Well is the other application sending anything back?
Can you see any responses being sent your way? (WMQExplorer)...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
rahul13.p |
Posted: Mon Dec 23, 2013 9:24 pm Post subject: |
|
|
Newbie
Joined: 23 Dec 2013 Posts: 4
|
@fjb_saper
Another application is sending response messages back when I am doing "outputQueue.get(sampleResponse, gmo); ". but the message is not of the corelated request. It seems whichever older message found in output queue,that message is returns. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Dec 24, 2013 7:44 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
This could be a timing problem. Remember that with WMQ your message is not available to the other party or even the channel) until committed. You need to look at your transaction boundaries...
And please remember that your request response pattern requires at least 2 transactions.
Remember as well that if you use JMS and an appserver the appserver's transaction might / will supersede the JMS transaction settings...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
rahul13.p |
Posted: Wed Dec 25, 2013 8:34 am Post subject: |
|
|
Newbie
Joined: 23 Dec 2013 Posts: 4
|
But this is standard code to achieve synchronous communication in MQ. I am not getting why it is not working.
If I am retrieving the message from response queue by correlation id then it should give me that message only. |
|
Back to top |
|
 |
smdavies99 |
Posted: Wed Dec 25, 2013 10:12 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
As my colleague says there you have to be aware of the various transaction boundaries.
Are you sure that you are really committing the outbound message?
The message may have been written to the queue but until it is comittend then no one else can read it.
IF that is ok, try removing the CORRELID Match and display the ID's received. The destination app could be mangling the copy of the CORREID it receives to the outbound CORRELID _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
rahul13.p |
Posted: Thu Dec 26, 2013 5:44 am Post subject: |
|
|
Newbie
Joined: 23 Dec 2013 Posts: 4
|
Issue get resolved by just making below code change
sampleResponse.correlationId=sampleRequest.messageId;
Now I am getting message related to request only. |
|
Back to top |
|
 |
|