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 » correlation id

Post new topic  Reply to topic
 correlation id « View previous topic :: View next topic » 
Author Message
nimojijeevan
PostPosted: Thu Feb 05, 2004 10:44 pm    Post subject: correlation id Reply with quote

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
View user's profile Send private message
vennela
PostPosted: Fri Feb 06, 2004 7:22 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
EddieA
PostPosted: Fri Feb 06, 2004 9:39 am    Post subject: Reply with quote

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
View user's profile Send private message
vennela
PostPosted: Fri Feb 06, 2004 11:59 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
RogerLacroix
PostPosted: Fri Feb 06, 2004 8:33 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
nimojijeevan
PostPosted: Thu Feb 19, 2004 10:07 pm    Post subject: correlation id Reply with quote

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
View user's profile Send private message
RogerLacroix
PostPosted: Fri Feb 20, 2004 7:19 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
douglasmhurst
PostPosted: Wed Jan 25, 2006 5:12 am    Post subject: Do you have a snippet of code... Reply with quote

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
View user's profile Send private message Send e-mail AIM Address
EddieA
PostPosted: Wed Jan 25, 2006 9:45 am    Post subject: Reply with quote

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
View user's profile Send private message
wschutz
PostPosted: Wed Jan 25, 2006 9:52 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address
douglasmhurst
PostPosted: Thu Jan 26, 2006 4:40 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address
mvic
PostPosted: Thu Jan 26, 2006 5:04 am    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

douglasmhurst wrote:
Java and MQ Api. We're not using JMS for this one.

You'll need to specify match options in the MQGetMessageOptions that you supply on the MQQueue.get(). Start here for details on the match options: http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/topic/com.ibm.mq.csqzak.doc/js00842.htm

I searched for a sample program specifying the necessary flag (MQMO_MATCH_CORRELID) but found nothing, much to my surprise!
Back to top
View user's profile Send private message
douglasmhurst
PostPosted: Thu Jan 26, 2006 6:28 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address
fjb_saper
PostPosted: Thu Jan 26, 2006 1:43 pm    Post subject: Reply with quote

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
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 » correlation id
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.