|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Convert the correlationId and the messageid |
« View previous topic :: View next topic » |
Author |
Message
|
frankzwo |
Posted: Thu Feb 23, 2006 8:52 am Post subject: Convert the correlationId and the messageid |
|
|
Newbie
Joined: 22 Dec 2005 Posts: 6
|
Hello,
i receive a message from a queue and would like to save the messageid and coreid in our database, because this ids are important for use, and we would like to use it in another program.
if i convert the messageid into a string i get the byte[] format of the variable
Excample messageIdStr = new String(aMessage.messageId.toString());
How can i convert it to a normal String (no Hexformat).
Thanks.
Frank |
|
Back to top |
|
 |
kevinf2349 |
Posted: Thu Feb 23, 2006 9:23 am Post subject: |
|
|
 Grand Master
Joined: 28 Feb 2003 Posts: 1311 Location: USA
|
You can't....it is a binary. This has been discussed in depth on this site. Try searching and everything will be explained. |
|
Back to top |
|
 |
mvic |
Posted: Thu Feb 23, 2006 9:38 am Post subject: Re: Convert the correlationId and the messageid |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
frankzwo wrote: |
How can i convert it to a normal String (no Hexformat). |
In order to render binary data as a string of characters, the best-accepted way is to take each byte and write it out as 2 characters of hex. For a 24-byte msgId or correlId, this means 48 characters of hex.
Permit me a little pseudocode (I could give you a real example in C, but not in Java, unfortunately):
Code: |
string = "";
foreach byte in byteArray
{
string = string + asHex(byte)
} |
|
|
Back to top |
|
 |
frankzwo |
Posted: Fri Feb 24, 2006 10:01 am Post subject: |
|
|
Newbie
Joined: 22 Dec 2005 Posts: 6
|
Hello again,
if i convert a string into the byte format for the messageid to put the message into a queue, there is no problem. if i convert the messageid from the queue into a string, there is a problem. i dont understand.
Code: |
MQMessage myMessage = new MQMessage();
myMessage.clearMessage();
myMessage.messageType = MQC.MQMT_DATAGRAM;
myMessage.writeString(m_quedaten);
myMessage.correlationId = m_coreid.getBytes(); // m_coreid is a string
myMessage.messageId = m_messageid.getBytes(); // m_messageid is a string
myMessage.format = MQC.MQFMT_STRING;
MQPutMessageOptions pmo = new MQPutMessageOptions();
System.out.println("Sending a message...");
queue.put(myMessage, pmo);
|
Is there no solution for this problem. The data in the messageid and coreids should be used and stored in a database, to identify the correct record later, and we would like to use it for verification purpouse.
Thanks for your help.
Frank |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Feb 24, 2006 10:05 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
If you want to do this, you have to convert each byte value in the byte[] into a hex representation, and store that.
You have to.
It is the only way to guarantee that you will be able to reconstruct the same ID later. And you will do that by converting the hex representation back into a byte value.
You can not simply convert a byte[] into a string, and save all the byte values - not all of them are valid characters! _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|