ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » Reading JMS message using MQ APIs

Post new topic  Reply to topic
 Reading JMS message using MQ APIs « View previous topic :: View next topic » 
Author Message
moonwalker
PostPosted: Tue Jun 02, 2009 3:17 am    Post subject: Reading JMS message using MQ APIs Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Tue Jun 02, 2009 3:04 pm    Post subject: Re: Reading JMS message using MQ APIs Reply with quote

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
View user's profile Send private message Send e-mail
moonwalker
PostPosted: Tue Jun 02, 2009 8:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Tue Jun 02, 2009 8:25 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
moonwalker
PostPosted: Tue Jun 02, 2009 8:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Wed Jun 03, 2009 7:24 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Reading JMS message using MQ APIs
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.