Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for a specific MsgID on a Queue.get()

Status
Not open for further replies.

jsaenz

Programmer
Mar 22, 2002
3
MX
Hi everybody,

I have a problem reading from a queue to get a message with an specific ID. My platform MQSeries5.2.1 using Java.

The issue i want to resolve is: I put a message on a queue1 to query a database, then, a server listening prgm. is reading the queue1, getting the message's text to query a database and return the resultet putting a message on a queue2. So, the client who made the query petition on a queue1, is reading the queue2 to seek for the message that contains the resultet. (In all process, i'm storing the messageId and correlationID trough MQMD Message Descriptor)

The problem is when i look for the message id on a queue2 i always get the first message on the queue

//my client code is pretty much like this....

class myClass{
private MQMD msgDef = new MQMD();

//Put message on queue1
private void putMessage(String pstrQry){
MQMessage msgPut = new MQMessage();
msgPut.messageType = MQC.MQMT_DATAGRAM;
msgPut.format = MQC.MQFMT_STRING;
msgDef.messageId = msgPut.messageId;
msgDef.correlationId = msgPut.correlationId;
msgPut.writeString(pstrQry);
putOptions.options = MQC.MQPMO_NEW_MSG_ID | MQC.MQPMO_NEW_CORREL_ID | MQC.MQPMO_FAIL_IF_QUIESCING;
qEnvio.put(msgPut, putOptions);
}

//Get message on queue2
private String getMessage(){
MQGetMessageOptions getMsgOpt = new MQGetMessageOptions();
getMsgOpt.options = MQC.MQGMO_WAIT | MQC.MQGMO_FAIL_IF_QUIESCING;
getMsgOpt.waitInterval = 15000;
getMsgOpt.matchOptions = MQC.MQMO_MATCH_MSG_ID | MQC.MQMO_MATCH_CORREL_ID;
MQMessage msgFromQueue = new MQMessage();
msgFromQueue.messageId = msgDef.messageId;
msgFromQueue.correlationId = msgDef.correlationId;
qRespuesta.get(msgFromQueue, getMsgOpt);
strRespuesta = msgFromQueue.readString(msgFromQueue.getMessageLength());
}
}

//Note i always store the MessageID and CorrelationID using a Message Descriptor using code...
private MQMD msgDef = new MQMD();



What could be the problem??
I have to specify others Put or Get MessageOptions??

I hope you can help me!
 
Some points:
i) You seem to have saved MsgId and CorrelId BEFORE the

qEnvio.put(msgPut, putOptions);

which generates a MsgId and CorrelId because you specify

putOptions.options = MQC.MQPMO_NEW_MSG_ID |
MQC.MQPMO_NEW_CORREL_ID |
MQC.MQPMO_FAIL_IF_QUIESCING;


The MsgId and CorrelId sent with the message will not be what was saved earlier. I would expect that what you see is a reply to msg1 when you expect reply for msg2 (i.e. always 1 msg out-of-step).

Try moving
msgDef.messageId = msgPut.messageId;
msgDef.correlationId = msgPut.correlationId;

after
qEnvio.put(msgPut, putOptions);


ii) In request/reply, you probably should use MQC.MQFMT_REQUEST and MQC.MQFMT_REPLY instead of MQC.MQFMT_DATAGRAM.

iii) A better use of MsgId and CorrelId is to have the server application assign the original (client's) MsgId into the CorrelId of the reply and allow MQ generate a unique MsgId. This ensures unique MsgId (by QMgr) for all messages. The client application will request match on CorrelId using the MsgId that MQ generated for the .put

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top