Author |
Message
|
moonwalker |
Posted: Tue Jun 02, 2009 3:17 am Post subject: Reading JMS message using MQ APIs |
|
|
 Apprentice
Joined: 02 Jun 2009 Posts: 42
|
Hi,
I have an MDB, deployed on WAS 6.0, which has a listener configured to a MQ Queue. The MDB after processing the message generates a response which is also posted to a MQ Queue. Before response is posted the MessageID of the request message is copied to the response message's Correlation ID.
The application that posts the request also persists the MessageID temporarily, sleeps for 30 seconds and then tries to read the response message on the response queue using below logic:
mqmessage.correlationID=<previously persisted message id>;
mqqueue.get(mqmessage);
An exception is thrown when the above code runs as the response queue does not contain any message with CorrID as specified above.
When the queue is browsed using MQ Explorer the messages have a new CorrID instead of the one set in the MDB.
Please help with a workaround for reading JMS messages using MQ APIs with a specified CorrID.
Thanks in advance. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jun 02, 2009 3:04 pm Post subject: Re: Reading JMS message using MQ APIs |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
moonwalker wrote: |
Hi,
I have an MDB, deployed on WAS 6.0, which has a listener configured to a MQ Queue. The MDB after processing the message generates a response which is also posted to a MQ Queue. Before response is posted the MessageID of the request message is copied to the response message's Correlation ID.
The application that posts the request also persists the MessageID temporarily, sleeps for 30 seconds and then tries to read the response message on the response queue using below logic:
mqmessage.correlationID=<previously persisted message id>;
mqqueue.get(mqmessage); |
Not the best of designs. You will always wait for 30 seconds even if the response is there in 1.
Try instead to set the wait time to 30 seconds and do an MQGET with WAIT. You will get the message as soon as it becomes available or wait for 30 seconds to time out.
moonwalker wrote: |
An exception is thrown when the above code runs as the response queue does not contain any message with CorrID as specified above.
When the queue is browsed using MQ Explorer the messages have a new CorrID instead of the one set in the MDB.
Please help with a workaround for reading JMS messages using MQ APIs with a specified CorrID.
Thanks in advance. |
This correlId business... hm I suspect has to do with the way you store it...
Is the message possibly undergoing multiple changes and the correlId is not getting set at each stop?
Show us some code and remember for messageId and correlId a byte is a byte is a byte... and you got 24 of them...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
moonwalker |
Posted: Tue Jun 02, 2009 8:12 pm Post subject: |
|
|
 Apprentice
Joined: 02 Jun 2009 Posts: 42
|
I have handled the timing part exactly, as said and its really a good thought.
Coming to the IDs, I have set the message ID in the request application as shown below.
mqMessage.correlationID = "1236183450696".getBytes();
The above line is only for testing purpose but we have different logic that has to be implemented for setting the message id.
In the MDB there isn't any logic involved for setting the CorrID, merely copies the message id to CorrID.
The same hardcoded constant is being lookedup in the response message's CorrID.
But what I can notice is that within the contents of the message I can see the expected CorrID. So I suspect that MQ is setting a separate message header wrapping the entire JMS message including its header settings.
How do we handle this new thing wherein the CorrID is now part of the mesaage body?
Is there any way? |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jun 02, 2009 8:25 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
as long as your correlId is less or equal to 24 bytes you should be good. The JMSCorrelationId gets transferred (for the first 24 bytes) to the MQMD correlId.
What I would suggest is that you change your MDB to do the following:
Check if the correlid is MQC.MQCI_NONE .
If it is move the messageId to the correlId. Else make the correlId a pass through...
Quote: |
The above line is only for testing purpose but we have different logic that has to be implemented for setting the message id. |
Don't. Best practice says: let MQ set message Id and correlId and have the app log those values... They'll have the advantage of being unique...
Have fun.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
moonwalker |
Posted: Tue Jun 02, 2009 8:52 pm Post subject: |
|
|
 Apprentice
Joined: 02 Jun 2009 Posts: 42
|
If the message id is less than 24 bytes then is it alright to put the below code in the MDB.
responseMessage.correlationID = MQC.MQCI_NONE;
The above line enables MQ to copy the message ID to the CorrID provided, the message id is less than 24 bytes. Am I correct?
Looks like now its possible to pick a message from the queue with a specified CorrID? |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jun 03, 2009 7:24 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
moonwalker wrote: |
If the message id is less than 24 bytes then is it alright to put the below code in the MDB.
responseMessage.correlationID = MQC.MQCI_NONE;
The above line enables MQ to copy the message ID to the CorrID provided, the message id is less than 24 bytes. Am I correct?
Looks like now its possible to pick a message from the queue with a specified CorrID? |
Don't know whatever gave you that idea. The line sets the correlationId to its initial low value (hex zeroes).
By the way if you let MQ set the correlId, like when MQ sets the message id it will only be available to the application after the put. _________________ MQ & Broker admin |
|
Back to top |
|
 |
|