Author |
Message
|
nimojijeevan |
Posted: Thu Feb 05, 2004 10:44 pm Post subject: correlation id |
|
|
Newbie
Joined: 05 Feb 2004 Posts: 3
|
Iam very new to MQ series, I want to generate a unique correlation id for each request, it is possible using MQ series java api, can any one please post the code how to do it.
Regards
Nimoji |
|
Back to top |
|
 |
vennela |
Posted: Fri Feb 06, 2004 7:22 am Post subject: |
|
|
 Jedi Knight
Joined: 11 Aug 2002 Posts: 4055 Location: Hyderabad, India
|
You can generate a unique number on your own and stick it in as correlationId. If you don't then MQ will generate a rondom correlationId and it will be unique.
Code: |
import com.ibm.mq.*;
import java.util.Random;
public class uniqueCorrelId extends Object {
public uniqueCorrelId (){
}
/**
* @param args the command line arguments
*/
public static void main (String args[]) {
try {
String QM1 = "QM1";
String QUEUE1 = "QC1";
MQQueueManager qmgr = new MQQueueManager(QM1 ) ;
System.out.println("Connected to QMGR " + QM1);
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_SET_IDENTITY_CONTEXT;
MQQueue InQueue = qmgr.accessQueue(QUEUE1 , openOptions, null, null, null);
MQMessage inMessage = new MQMessage();
inMessage.writeString("Another message");
//Generating random number
//
java.util.Random R1 = new Random();
byte [] corId = new byte[24];
R1.nextBytes(corId);
//
inMessage.correlationId = corId ;
InQueue.put(inMessage);
System.out.println("corId is :" + inMessage.correlationId);
InQueue.close();
qmgr.disconnect() ;
}
catch(MQException ex){
System.out.println("MQ Error - Reason code :" + ex.reasonCode);
}
catch (Exception e){
System.out.println("Error : " + e);
}
}
} |
|
|
Back to top |
|
 |
EddieA |
Posted: Fri Feb 06, 2004 9:39 am Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Quote: |
If you don't then MQ will generate a rondom correlationId |
No. If you don't specify a CorrelationID, then MQ leaves it as 'blank'. Maybe you were thinking of MessageId.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
vennela |
Posted: Fri Feb 06, 2004 11:59 am Post subject: |
|
|
 Jedi Knight
Joined: 11 Aug 2002 Posts: 4055 Location: Hyderabad, India
|
Quote: |
Maybe you were thinking of MessageId.
|
Right.
CorrelId is blank. Thanks for the correction. |
|
Back to top |
|
 |
RogerLacroix |
Posted: Fri Feb 06, 2004 8:33 pm Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
Hi,
If you want the queue manager to generate a new (unique) CorrelID for your message then set the CorrelID to MQCI_NONE and set the PMO option of MQPMO_NEW_ CORREL_ID (you must do both).
Regards,
Roger Lacroix _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
nimojijeevan |
Posted: Thu Feb 19, 2004 10:07 pm Post subject: correlation id |
|
|
Newbie
Joined: 05 Feb 2004 Posts: 3
|
Many thanks for your replies, Iam able to generate correlation id Using the queue manager, but when iam retriving the same message from queue and printing the correlation id, it prints a different correlation id, not the one which is generated earlier. please can anybody explain why is this happening and how I should make sure that the both the correlation ids are same. |
|
Back to top |
|
 |
RogerLacroix |
Posted: Fri Feb 20, 2004 7:19 am Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
Hi,
After the queue manager has generated the "new unique" CorrelID YOU MUST save it to a byte array and then set the next message's with the saved CorrelID.
Regards,
Roger Lacroix _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
douglasmhurst |
Posted: Wed Jan 25, 2006 5:12 am Post subject: Do you have a snippet of code... |
|
|
Newbie
Joined: 25 Jan 2006 Posts: 3 Location: Fairfax, VA
|
... for selecting a message off the queue based on the correlation ID?
We have one queue we're going to simply pop messages off of. Each will have a correlation ID that tells us, ok, now go to this other queue and pop all the messages that have this same correlation ID. |
|
Back to top |
|
 |
EddieA |
Posted: Wed Jan 25, 2006 9:45 am Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
And the question/problem is ? ? ?
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
wschutz |
Posted: Wed Jan 25, 2006 9:52 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
EddieA wrote: |
And the question/problem is ? ? ?
Cheers, |
You have read the subject line as part of the body....
douglasmhurst: what language do you want it for?? _________________ -wayne |
|
Back to top |
|
 |
douglasmhurst |
Posted: Thu Jan 26, 2006 4:40 am Post subject: |
|
|
Newbie
Joined: 25 Jan 2006 Posts: 3 Location: Fairfax, VA
|
Java and MQ Api. We're not using JMS for this one. |
|
Back to top |
|
 |
mvic |
Posted: Thu Jan 26, 2006 5:04 am Post subject: |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
|
Back to top |
|
 |
douglasmhurst |
Posted: Thu Jan 26, 2006 6:28 am Post subject: |
|
|
Newbie
Joined: 25 Jan 2006 Posts: 3 Location: Fairfax, VA
|
Just this morning, I found this, which I've integrated into my code
If a correlationId string is passed to my method...
MQMessage retrievedMessage = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
// If a correlationId is passed, we assume that we only want messages
// with that correlationId
if (correlationId != null && correlationId.length() > 0)
{
//Setting the Correlation ID
gmo.matchOptions = MQC.MQMO_MATCH_CORREL_ID;
byte[] corIdBytes = new byte[correlationId.length()];
corIdBytes = correlationId.getBytes("US-ASCII");
retrievedMessage.correlationId = corIdBytes;
}
// Now this code will only 'readFully' message with the same correlationId
system_default_local_queue.get(retrievedMessage, gmo);
int len = retrievedMessage.getMessageLength();
retrievedMessage.readFully(br, 0, len);
Please feel free to use this to help anyone else asking a similar question |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Jan 26, 2006 1:43 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
BAD CODING:
you may know you want Correlid "HITLIST"
But you have no idea who put that correlid on the message. If a different CCSID was used the byte array will not be the same and you may not get the right answer (no message will match your correlid).
Instead of translating the String into the correlid just use existing byte arrays. One of the most common pattern is to use the messageid and pass it to the correlationId if you are the server program.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|