Broker 10.5 | webMethods Broker Documentation | webMethods Broker Messaging Programmer's Guide | Coding Messaging Client Applications | JMS Request-Reply Application with a Message Selector | Application Code | Linking a Reply to a Request Message
 
Linking a Reply to a Request Message
To configure a JMS request-reply message pair, you need to link the two together through application code.
Because each request message expects a reply, the JMSReplyTo header field of the request message must be set to the destination to which the reply will be sent. In this example, you set it to the replyQueue (of type Queue) declared in the RequestorApplication.java class definition, as shown in the following line of code. The message object msg is the request message:
msg.setJMSReplyTo(replyQueue);
Next, in the server application, in the message listener's onMessage() method, the message ID header information of the request message is copied to a field in the reply message. This is done in a single line of code by:
*Calling the setJMSCorrelationID() method on the reply message object.
*Getting the value for the reply message JMSCorrelationID header field through message.getJMSMessageID(); this sets the value of the field to the request message header ID.
reply.setJMSCorrelationID(message.getJMSMessageID());
The following figure summarizes the relationships that must be coded between the JMS header fields of the request and reply messages:
After the request and reply messages are linked, a send is issued for the reply message; however, the message will not be sent until an explicit commit is executed. This is because the session to which the reply message belongs is defined as transacted in ServerApplication.setup(). The transaction is explained more fully in Implementing a Local Transaction.
sender.send(message.getJMSReplyTo(), reply);
In the requestor application, in lookupCustomerInfo(), the JMSMessageID header field value for the request message is saved for later use as a means of validating the reply.
String pendingMsgID = msg.getJMSMessageID();
The method then validates that the reply is linked to the proper request message (checks to see which reply it is) and initiates further processing of the reply.

while (true)
{
Message replyMessage = receiver.receive(REPLY_WAIT_TIME);
...
if(!pendingMsgID.equals(replyMessage.getJMSCorrelationID()))
...
}