Author |
Message
|
VinothRaja |
Posted: Wed Jan 30, 2013 7:45 am Post subject: Issue in Correlating request message to resp message in Java |
|
|
Newbie
Joined: 30 Jan 2013 Posts: 7
|
Hi,
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.
Program used:
Code: |
import com.ibm.mq.*; // Include the WebSphere MQ classes for Java package
import com.ibm.mq.constants.CMQC;
import com.ibm.mq.constants.MQConstants;
public MQSample() {
try {
MQEnvironment.hostname = "MQSEREVER";
MQEnvironment.channel = "CLIENT";
MQEnvironment.port = 1414;
// Create a connection to the queue manager
qMgr = new MQQueueManager(qManager);
// Set up the options on the queue we wish to open...
// Note. All WebSphere MQ Options are prefixed with MQC in Java.
int openOptions = MQConstants.MQOO_OUTPUT;
// Now specify the queue that we wish to open,
// and the open options...
MQQueue system_default_local_queue = qMgr.accessQueue(
"REQ.INQ.01", openOptions);
// Define a simple WebSphere MQ message, and write some text in UTF
// format..
MQMessage request = new MQMessage();
//************* New
// Set reply queue
request.replyToQueueName = "RPL.INQ.01";
request.writeString("<Msg></Msg>");
MQPutMessageOptions pmo = new MQPutMessageOptions();
// put the message on the queue
system_default_local_queue.put(request, pmo);
// get the message back again...
// First define a WebSphere MQ message buffer to receive the message
// into..
MQMessage retrievedMessage = new MQMessage();
System.out.println("request.messageId" + request.correlationId);
retrievedMessage.correlationId = request.correlationId;
System.out.println("retrievedMessage.messageId"
+ retrievedMessage.messageId);
// Set the get message options...
MQGetMessageOptions gmo = new MQGetMessageOptions(); // accept the
// defaults
gmo.waitInterval = 2000;
System.out.println("Correlation ID to use for receive: " + retrievedMessage.correlationId);
System.out.println("Supported character set to use for receive: " + retrievedMessage.characterSet);// same as
// MQGMO_DEFAULT
openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT;
// get the message off the queue...
system_default_local_queue = qMgr.accessQueue(
"RPL.INQ.01", openOptions);
system_default_local_queue.get(retrievedMessage, gmo);
System.out.println("The receive message character set is: " + retrievedMessage.characterSet);
// And prove we have the message by displaying the UTF message text
String msgText = retrievedMessage.readStringOfCharLength(retrievedMessage.getDataLength());
System.out.println("The message is: " + msgText);
// Close the queue...
system_default_local_queue.close();
// Disconnect from the queue manager
qMgr.disconnect();
} |
|
|
Back to top |
|
 |
Vitor |
Posted: Wed Jan 30, 2013 8:01 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
I don't see in the get message options where you're telling WMQ you want the message that matches the correl id you're using not the first one in the queue. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
VinothRaja |
Posted: Wed Jan 30, 2013 8:11 am Post subject: |
|
|
Newbie
Joined: 30 Jan 2013 Posts: 7
|
Hi,
Thanks for your quick response.
I am assigning request correlation ID in response MQMessage field
MQMessage retrievedMessage = new MQMessage();
retrievedMessage.correlationId = request.correlationId;
and passing it to
system_default_local_queue.get(retrievedMessage, gmo);
is it not the correct way.
Please advice.
Thanks
Vinoth |
|
Back to top |
|
 |
Vitor |
Posted: Wed Jan 30, 2013 8:27 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
VinothRaja wrote: |
is it not the correct way. |
It's not the complete way. I think you not only need to provide the id you're looking for, but tell WMQ to use it via MQMO_MATCH_CORREL_ID as indicated here, here and here. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
VinothRaja |
Posted: Wed Jan 30, 2013 8:44 am Post subject: |
|
|
Newbie
Joined: 30 Jan 2013 Posts: 7
|
Hi,
Thanks
I have assigned the match options value. We are using MQ 7.5. so I have used MQConstants.MQMO_MATCH_CORREL_ID.
Please confirm whether it is correct.
Please also advice whether wmqjava approach can be used for Production systems or should i check on the JMS options.
MQGetMessageOptions gmo = new MQGetMessageOptions(); gmo.matchOptions = MQConstants.MQMO_MATCH_CORREL_ID;
gmo.waitInterval = 2000;
openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF| MQConstants.MQOO_OUTPUT;
system_default_local_queue= qMgr.accessQueue("RPL.INQ.01", openOptions);
system_default_local_queue.get(retrievedMessage, gmo);
Thanks
Vinoth |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Jan 30, 2013 8:51 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
So you have shown code that asks for MQ to match the correlation id you have supplied.
You have not shown code that supplies the correlation id to be matched against. |
|
Back to top |
|
 |
VinothRaja |
Posted: Wed Jan 30, 2013 8:59 am Post subject: |
|
|
Newbie
Joined: 30 Jan 2013 Posts: 7
|
Hi,
Here is the logic used to assign the ID. I assign the correlation id generated for MQMessage Request to response one
Please confirm..
MQMessage request = new MQMessage();
request.replyToQueueName = "RPL.INQ.01";
request.writeString("<Msg> </Msg>");
MQPutMessageOptions pmo = new MQPutMessageOptions(); system_default_local_queue.put(request, pmo);
MQMessage retrievedMessage = new MQMessage();
retrievedMessage.correlationId = request.correlationId;
Thanks
Vinoth |
|
Back to top |
|
 |
VinothRaja |
Posted: Thu Feb 07, 2013 9:30 am Post subject: |
|
|
Newbie
Joined: 30 Jan 2013 Posts: 7
|
Hi,
Thanks for the support.
I could map the message ID in request to correlation ID and get the correct response.
Now I want to use the default connection pooling to implement connectionn pooling.
IBM examples shows to use MQPoolToken token=MQEnvironment.addConnectionPoolToken();
and MQEnvironment.removeConnectionPoolToken(token);
Could you please advice on how it can be used in the multi threaded applications.
Shoul I do below everytime when I need connection?
MQPoolToken token=MQEnvironment.addConnectionPoolToken();
and do the below after getting the response?
and MQEnvironment.removeConnectionPoolToken(token);
It is bit confusing. Please clarify
Thanks
Vinoth |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Feb 07, 2013 10:25 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
VinothRaja wrote: |
Hi,
Here is the logic used to assign the ID. I assign the correlation id generated for MQMessage Request to response one
Please confirm..
MQMessage request = new MQMessage();
request.replyToQueueName = "RPL.INQ.01";
request.writeString("<Msg> </Msg>");
MQPutMessageOptions pmo = new MQPutMessageOptions(); system_default_local_queue.put(request, pmo);
MQMessage retrievedMessage = new MQMessage();
retrievedMessage.correlationId = request.correlationId;
Thanks
Vinoth |
So please explain why you are surprised that this does not work.
You send the message without a correlation Id and you expect the returning message to have one. However you do not define any correlation ID options.
you should perhaps try and apply some common logic to your problem.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
VinothRaja |
Posted: Thu Feb 07, 2013 6:32 pm Post subject: |
|
|
Newbie
Joined: 30 Jan 2013 Posts: 7
|
Hi,
I have solved it by setting below . Yes it was my mistake that I didn't set the correlation ID.
MQMessage retrievedMessage = new MQMessage();
retrievedMessage.correlationId = request.correlationId;
// Set the get message options...
MQGetMessageOptions gmo = new MQGetMessageOptions(); // accept the
// defaults
gmo.matchOptions = MQConstants.MQMO_MATCH_CORREL_ID;
gmo.waitInterval = 4000;
Thanks
Vinoth |
|
Back to top |
|
 |
VinothRaja |
Posted: Fri Feb 08, 2013 5:41 am Post subject: |
|
|
Newbie
Joined: 30 Jan 2013 Posts: 7
|
Hi,
Could you please advice on implemeting connection pooling?
IBM examples shows to use MQPoolToken token=MQEnvironment.addConnectionPoolToken();
and MQEnvironment.removeConnectionPoolToken(token);
Could you please advice on how it can be used in the multi threaded applications.
I bit confused on when to call add and remove Connection Pool..
Thanks
Vinoth |
|
Back to top |
|
 |
|