Author |
Message
|
priyasharma |
Posted: Fri Apr 09, 2004 6:24 am Post subject: Matching reply message with request message in JMS |
|
|
Novice
Joined: 09 Apr 2004 Posts: 10
|
Can somebody tell me about the concept of matching reply message with request message in JMS??I have an idea that i need to set correlation id while sending the message at sender side.On the receiver end,while sending back the reply,do I need to again set correlation id or do I need not set anything while sending back reply??I am not clear with the concept.Please help me. |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Apr 09, 2004 6:46 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
It's the same in JMS as it is in everything else. The requestor keeps track of the message ID for the request message, and matchs that against the correlation ID of the reply message.
Code: |
//Send request
m_QueueSender.send(
message,
JMSC.MQJMS_PER_QDEF,
JMSC.MQJMS_PRI_QDEF,
60 * 60 * 1000);
String msgID = message.getJMSMessageID();
//Wait for Reply
m_QueueReceiver = qRcvrSession.createReceiver(replyQueue, "JMSCorrelationID='"+corrID+"'");
TextMessage replyMsg = (TextMessage) m_QueueReceiver.receive(60*60 * 100);
|
The server application copies the message ID from the request message into the correlation ID of the reply. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
priyasharma |
Posted: Fri Apr 09, 2004 6:50 am Post subject: |
|
|
Novice
Joined: 09 Apr 2004 Posts: 10
|
|
Back to top |
|
 |
priyasharma |
Posted: Fri Apr 09, 2004 7:23 am Post subject: |
|
|
Novice
Joined: 09 Apr 2004 Posts: 10
|
Do I need to declare a message of type ObjectMessage if this was my reply message type and invoke getJMSCorrelationId method on this instance before following line :
m_QueueReceiver = qRcvrSession.createReceiver(replyQueue, "JMSCorrelationID='"+corrID+"'"); |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Apr 09, 2004 7:36 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Actually, there's a slight mistake in the code I posted.
I copied the code from something that has the send in one method and the wait for reply in another.
The field in my code called 'msgID' is the same as the field called 'corrID'.
So use one or the other in both places. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
priyasharma |
Posted: Fri Apr 09, 2004 7:41 am Post subject: |
|
|
Novice
Joined: 09 Apr 2004 Posts: 10
|
ya,now its working.Thanks again. |
|
Back to top |
|
 |
|