Author |
Message
|
magesh_chandren |
Posted: Sun Apr 04, 2004 8:49 pm Post subject: Problem with retrieving a specific message with MQ |
|
|
Novice
Joined: 16 Feb 2004 Posts: 12
|
Hi All,
Iam using MQ Java client to connect to a MQ Server. This is what I do in steps.
1. Access a queue (say Q1) and put a message MSG1 into it
2. Another program waits for a message on this request queue(Q1) and puts a message MSG2 into another queue(Q2) with the correlation ID of MSG2 to be the messageID of MSG1
ie MSG2.correlationID = MSG1.messageID
3. I wait for a message on Q2 with a message whose correlation ID is MSG1.messageID
For the above sequence of steps, sometimes I receieve messages for which Iam not actually waiting for. Can anyone help me on this ? Where am I exactly going wrong.
FYI, I checked the message ID of MSG1. Each time I put this into the Queue, it is unique. So there could be only one unique incoming message on Q2. But how is that I receive someother message and not the intended one ?
This is the actual code Iam using
//************Start Code***************
openOptions = MQC.MQOO_INPUT_SHARED | MQC.MQOO_ALTERNATE_USER_AUTHORITY;
replyQueue = qMgr.accessQueue(mqSet.queueRply,openOptions,null,null,mqSet.queueUID);
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.waitInterval = Integer.parseInt(mqSet.rpcWait);
gmo.options = MQC.MQGMO_WAIT;
gmo.matchOptions = MQC.MQMO_MATCH_CORREL_ID;
MQMessage retrievedMessage = new MQMessage();
retrievedMessage.correlationId = sendingMsg.messageId;
replyQueue.get(retrievedMessage,gmo);
//***************End Code***************
Pls Help!!
Thanks & Regards
Magesh |
|
Back to top |
|
 |
jefflowrey |
Posted: Sun Apr 04, 2004 8:54 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You didn't get an answer the last time you asked this question: http://www.mqseries.net/phpBB2/viewtopic.php?p=56875
I suspect you didn't get an answer because you didn't provide enough information about how you are actually putting your original request message, how you know for sure you are getting "some other message", and what that other message looks like. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
magesh_chandren |
Posted: Sun Apr 04, 2004 11:35 pm Post subject: Re:Retrieving speific message |
|
|
Novice
Joined: 16 Feb 2004 Posts: 12
|
Hi Jeff,
I have 2 queues. Request Q and Reply Q.
To put it simpler, I have a simple java client program which puts message into the request queue (say I put the message "Message1") and waits for a particular intreval.
I have a CICS program running at mainframe which receives this message and sends back the message "Message1" on a reply queue(this message has the correlationID equal to the message ID of "Message1" on request queue).
The java client waits for a message on the reply queue with a message whose correlationID is the same as messageID of the message put on the request queue. Now as "Message1" has in its correlationID the messageID of the sent one, I am retrieving it correctly.
But it doesnt always happen the same way, when Iam running multiple instances of the Java client with different messages put into the request queue.
Take the situation below
1. Java client1 puts message "Howdy Partner" and Java client2 puts message "Hello World".
2 For the message "Howdy Partner", the CICS PROGRAM doesnt gets triggered. and does not put back a message
3. When I have put the message "Hello World", I get back "Howdy Partner". How is this possible, when my java client waits for "Hello World".
Now can you tell me where Iam going wrong ?
Iam enclosing the complete Java Code for your reference.
private static void init(){
MQEnvironment.hostname =hostname;
MQEnvironment.channel =channel;
MQEnvironment.port = 6001;
MQEnvironment.userID="pwd1";
}
public static void main(String[] args) throws MQException{
MQQueue request_queue = null;
MQQueue reply_queue = null;
init();
//Access the Q Manager
qMgr =new MQQueueManager(qManager);
int openOptions = MQC.MQOO_ALTERNATE_USER_AUTHORITY|MQC.MQOO_OUTPUT|MQC.MQOO_SET_IDENTITY_CONTEXT;
//Access the Request Queue
request_queue = qMgr.accessQueue(requestqueue ,openOptions,null,null,"pwd");
MQMessage sending_msg =new MQMessage();
sending_msg.userId = "pwd";
sending_msg.replyToQueueName = replyQueue;
sending_msg.format = MQC.MQFMT_STRING;
sending_msg.writeString("Hello World");
sending_msg.expiry = 600;
MQPutMessageOptions pmo =new MQPutMessageOptions();
pmo.options = MQC.MQPMO_SET_IDENTITY_CONTEXT|MQC.MQPMO_NEW_MSG_ID;
//Access the ReplyQueue
openOptions = MQC.MQOO_INPUT_SHARED | MQC.MQOO_ALTERNATE_USER_AUTHORITY;
reply_queue = qMgr.accessQueue(replyQueue,openOptions,null,null,"pwd");
MQMessage retrievedMessage = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.waitInterval = 6000;
gmo.options = MQC.MQGMO_WAIT;
retrievedMessage.correlationId = sending_msg.messageId;
gmo.matchOptions = MQC.MQMO_MATCH_CORREL_ID;
request_queue.put(sending_msg,pmo);
reply_queue.get(retrievedMessage,gmo);
reply_queue.close();
String msgText =retrievedMessage.readString(11);
System.out.println("The message is:" + msgText);
}
Am I going wrong somewhere in the statements
retrievedMessage.correlationId = sending_msg.messageId;
gmo.matchOptions = MQC.MQMO_MATCH_CORREL_ID;
Is that the way, I should wait for a message with a particular correlationID (ie by assigning correlationID (of the message to be retrieved) to the value which I expect in it) ?
Hope I was clear to some extent this time.
Thanks Again
Magesh |
|
Back to top |
|
 |
crossland |
Posted: Mon Apr 05, 2004 1:46 am Post subject: |
|
|
Master
Joined: 26 Jun 2001 Posts: 248
|
If you want to receive the response to a request, getting a response message whose correlation id matches the message id of the original request works (I have designed and implemented applications that do this).
Have you checked that the remote end is correctly setting the correlation identifier of the response to the message identifier of the correct request?
Regards,
Tim Crossland
http://www.solent-consultancy.com |
|
Back to top |
|
 |
gunter |
Posted: Mon Apr 05, 2004 4:12 am Post subject: |
|
|
Partisan
Joined: 21 Jan 2004 Posts: 307 Location: Germany, Frankfurt
|
I'm not sure!
If you generate a new messageid, this is done after the put. _________________ Gunter Jeschawitz
IBM Certified System Administrator - Websphere MQ, 5.3 |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Apr 05, 2004 4:27 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
gunter wrote: |
I'm not sure!
If you generate a new messageid, this is done after the put. |
This is a good point. The line in his code
Quote: |
retrievedMessage.correlationId = sending_msg.messageId;
|
needs to appear after
Quote: |
request_queue.put(sending_msg,pmo); |
_________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
techno |
Posted: Wed May 12, 2004 10:08 am Post subject: |
|
|
Chevalier
Joined: 22 Jan 2003 Posts: 429
|
Doing the samething! relating the requests and replies. Taking MsgId of requested msg as string and setting it to correlationid of reply msg. requesting side is not able to find the corresponding reply msg. But I can see reply msg in the queue
Do JMSCorrealtionIDs on look differently when (msg)printed and (msg)browsed using amqsbcg? I see X' prepending and id also changed while browse. Does it change the format?
Any links are appreciated.
Thanks |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed May 12, 2004 10:59 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
techno wrote: |
Taking MsgId of requested msg as string |
Why?
It's not a string unless you've gone to some trouble to make sure it is.
************************
Edit:
Sorry, you're talking about the result of JMSGetMessageID or JMSGetCorrelationID.
These are Strings, and they are converted as you ask. The reason they are converted in the way they are is because they aren't strings in the MQMD. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
techno |
Posted: Wed May 12, 2004 12:24 pm Post subject: |
|
|
Chevalier
Joined: 22 Jan 2003 Posts: 429
|
In my code:
One side (Unix: Requesting and reciving reply Side):
Code: |
String corelationId = msgSent.getJMSMessageID();
qReceiver = qSession.createReceiver(qQueueReceiver, "JMSCorrelationID = '"+corelationId+"'");
returnedMsg = qReceiver.receive(5000); |
On other side(MainFrame:receiving request and Replying Side):
Code: |
corelationId = receivedMsg.getJMSMessageID();
replyMsg.setJMSCorrelationID(corelationId ) |
I am very sure that I am doing something wrong! May be I need to do some conversion. Pls help. |
|
Back to top |
|
 |
techno |
Posted: Wed May 12, 2004 5:33 pm Post subject: |
|
|
Chevalier
Joined: 22 Jan 2003 Posts: 429
|
any help? Do I have to do any conersion. On mainframe, I am printing correlatioId after the reply is sent. It is same as what has been sent from Unix. But on Unix, while receiving this reply, I see a different correlationId. Is it because of ASCII/EBCDIC??? |
|
Back to top |
|
 |
bower5932 |
Posted: Wed May 12, 2004 7:05 pm Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
I can't admit to following this thread. However, I can tell you that one of the very common misconceptions is that the MessageId and CorrelationId are part of what gets converted as a message goes cross-platform. These fields are considered binary (MQBYTE24) and are NOT converted. If you are putting text into them and expecting to manipulate it on a second platform, it won't work. |
|
Back to top |
|
 |
techno |
Posted: Thu May 13, 2004 9:35 am Post subject: |
|
|
Chevalier
Joined: 22 Jan 2003 Posts: 429
|
I could match the correlationid of reply message when I put some arbitrary string. I don't know what is the error I am making when correlationId is equated with mq generated messageid.
There is another problem now. If I fill all the 24 chracters, qReceiver with the selector is able to grab the reply. If the width of correlationId is less than 24, qReceiver is failing to grab the reply. Tried to put blanks (24 - number of characters).... it could not!!! |
|
Back to top |
|
 |
|