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 API Support » Setting Correlation ID

Post new topic  Reply to topic
 Setting Correlation ID « View previous topic :: View next topic » 
Author Message
swat
PostPosted: Tue Jun 27, 2006 10:45 pm    Post subject: Setting Correlation ID Reply with quote

Newbie

Joined: 30 Jan 2006
Posts: 4

Hi,

I am trying to set the correlation id, but when I browse the message in a Q it shows me the truncated value in correlation identifier in MQ. For ex if I am passing correlation ID = 414d5120737761746565202020202020d9cfa044200c9902, the message correlation id that gets set is 414d51207377617465652020.

I want the exact correlation id to be posted. Can u please help me in this regard.

My Program is -

import com.ibm.mq.*;
import java.io.*;

public class Sender {

private static MQQueueManager qMgr;

public Sender() {
super();
}

public static void main(String args[]) {
try {
if (args.length < 1) {
System.out.println("Missing queue name: "
+ "Sender <queue name> <qmgr name (optional)>");
} else {
System.out.println("Sender started...");
// create a new instance of the sample program
Sender Sender = new Sender();
//qMgr = new MQQueueManager(args[1]);
qMgr = new MQQueueManager("swatee");
int openOptions = MQC.MQOO_OUTPUT;
MQQueue q =
qMgr.accessQueue("ivrinqueue", openOptions, null, null, null);
// call method to send messages
try {
// Define a MQ message buffer
MQMessage mBuf = new MQMessage();
// create message options
MQPutMessageOptions pmo = new MQPutMessageOptions();
// accept defaults
pmo.options = MQC.MQPMO_NONE; // use defaults
System.out.println("Enter text to send, blank line to exit");
String xml = "<?xml version='1.0'?><BookCatalogue xmlns='http://www.publishing.org' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.publishing.org BookCatalogue.xsd'><Book><Title>Illusions The Adventures of a Reluctant Messiah</Title><Author>Richard Bach</Author><Date>1977</Date><ISBN>0-440-34319-4</ISBN><Publisher>Dell Publishing Co.</Publisher></Book></BookCatalogue>";
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String runShow = xml;
System.out.println("dkkdklo");
String co = args[0];
System.out.println("* please do not use *" + co);
do {
runShow = br.readLine();
if (runShow.length() > 0) {
mBuf.clearMessage(); // reset the buffer
mBuf.correlationId = co.getBytes(); // set correlationId
mBuf.messageId = MQC.MQMI_NONE; // set messageId
mBuf.writeString(runShow); // set actual message
System.out.println("--> writing message to queue");
q.put(mBuf, pmo); // put the message out on the queue
}
} while (runShow.length() > 0);
} catch (MQException ex) {
System.out.println("MQ exception occurred : Completion code "
+ ex.completionCode
+ " Reason code "
+ ex.reasonCode);
} catch (java.io.IOException ex) {
System.out.println(
"An error occurred reading from message buffer: " + ex);
}

// clean up connection
q.close();
qMgr.disconnect();
System.out.println("Sender ended...");
}

} catch (MQException ex) {
System.out.println(
"WMQ exception occurred : Completion code "
+ ex.completionCode
+ " Reason code "
+ ex.reasonCode);
}
}
}


Thanks and regards
Swat


Last edited by swat on Tue Jun 27, 2006 10:52 pm; edited 1 time in total
Back to top
View user's profile Send private message
elvis_gn
PostPosted: Tue Jun 27, 2006 10:47 pm    Post subject: Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

Hi swat,

Your code please.

Regards.
Back to top
View user's profile Send private message Send e-mail
swat
PostPosted: Tue Jun 27, 2006 10:59 pm    Post subject: Reply with quote

Newbie

Joined: 30 Jan 2006
Posts: 4

Sorry I forgot to paste code I updated my query. Please check that


Thanks and regards
Swat
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Jun 28, 2006 3:27 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Your problem is easy to understand:

you have a confusion between a true byte array and its representation.
MessageId and correlationId are true byte arrays of (24) bytes.
The text representation of the byte array is String of 48 characters==>
hex value = 00 to FF for one byte.

You just cannot use:

String co = mystringhexrepresentation;
set msg.correlationId(co.getBytes());

Your byte array has 48 bytes each representing the ascii value of the character representing the hex value of the array you want....
Missed the race by more than a boatlength there...

You need to build your byte array from the representation of the bytes.
Check into Byte.decode()

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
kevinf2349
PostPosted: Wed Jun 28, 2006 6:20 pm    Post subject: Reply with quote

Grand Master

Joined: 28 Feb 2003
Posts: 1311
Location: USA

This reminds me a war story of mine.

I had been at my new employer for just 3 weeks when in walk these 'MQ experts' from an outside Consulant company proposing an application solution that requires 64 bytes to be passed to identify the sender in the correlid feild.

Ermmmm say I....correlid is only 24 bytes long I tell the 'experts'. Well make it bigger they say.

I tell them just as soon as IBM do; I will.

Fastforward a few days and a status report claims MQ on z/OS can't support 64 bytes in the correlid field. I suitably remind them that this is an across the board deal not just z/OS.

Amended report reads....Kevin is refusing to increase the correlid field so we propose......

AGHHHHHHHH!


Experts! Ex = has been ;Spurt = a drip under pressure
Back to top
View user's profile Send private message
swat
PostPosted: Wed Jun 28, 2006 9:41 pm    Post subject: Reply with quote

Newbie

Joined: 30 Jan 2006
Posts: 4

Thanks a lot for the solution..

...

Cheers!!!
Swat
Back to top
View user's profile Send private message
karthik_pe
PostPosted: Fri Feb 09, 2007 9:48 am    Post subject: correlation Id getting truncated in response Reply with quote

Newbie

Joined: 09 Feb 2007
Posts: 4

I am setting a 48 length correlation id to the response. The response is sent and at the receiver end, they are getting it truncated and only first 24 characters are taken as correlation id.

My question is how this correlation id got truncated from 48 characters to 24 characters. I send the 48 characters as a byte array.

Look at the code snippet :
str="657788......."; // comes to 48 numbers
message.correlationid = str.getBytes();

I got a chance to look at another post in this forum with the same problem and a reply saying to use a Byte.decode() to avoid this truncation.

Can anyone please let me know how to use the Byte.decode so that I can avoid the correlationid value getting truncated.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Fri Feb 09, 2007 10:14 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

What does the Sun Javadoc for Byte.decode() say?


_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
karthik_pe
PostPosted: Fri Feb 09, 2007 10:37 am    Post subject: Reply with quote

Newbie

Joined: 09 Feb 2007
Posts: 4

According to javadoc, the decode method returns a Byte output.
But how this helps in the truncation...Can you please tell me by using this decode how we can convert 48 character to 24???


One more thing what I noted down is, at the receiver end, they use MQ GUI Browser. In that, when we see the properties of a message in queue, under Identifier tab, I could see message id and correlation id.

In correlation id, i could see 2 text boxes.
The first text box holds the first 24 characters of the value what i set (actually I set 48 characters).
And below that one more text box which has some numbers in it.

My question is which text box is the correct correlation id?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sat Feb 10, 2007 8:07 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

For your information:

Byte.decode("FF") will return a byte object of value -1 (signed).
So this will allow you to transform the hex representation of the value back into the value....

Anyway you should not have to use this.
Just set the correlId to the incoming message's messageId.
Don't even bother looking at the values except as an audit and that is in debug logging....

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
tleichen
PostPosted: Wed Feb 14, 2007 8:08 am    Post subject: Reply with quote

Yatiri

Joined: 11 Apr 2005
Posts: 663
Location: Center of the USA

fjb_saper wrote:
Your problem is easy to understand:

you have a confusion between a true byte array and its representation.
MessageId and correlationId are true byte arrays of (24) bytes.
The text representation of the byte array is String of 48 characters==>
hex value = 00 to FF for one byte.

You just cannot use:

String co = mystringhexrepresentation;
set msg.correlationId(co.getBytes());

Your byte array has 48 bytes each representing the ascii value of the character representing the hex value of the array you want....
Missed the race by more than a boatlength there...

You need to build your byte array from the representation of the bytes.
Check into Byte.decode()

Enjoy
Why is it that so many java programmers these days do not understand this?
_________________
IBM Certified MQSeries Specialist
IBM Certified MQSeries Developer
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Feb 14, 2007 8:11 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

tleichen wrote:
Why is it that so many java programmers these days do not understand this?

Because nobody teaches Java programmers what a "byte" is.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
rpm08
PostPosted: Wed Apr 02, 2008 10:55 am    Post subject: correlationID size Reply with quote

Newbie

Joined: 02 Apr 2008
Posts: 5

hi swat

i am getting same problem as u got for correlation id.
i will appreciate you , if u forward me solution for correlation id


rpm
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » Setting 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.