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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl MQSeries 1

Status
Not open for further replies.

swisschris

IS-IT--Management
Aug 29, 2005
14
CH
Hi there,
does anybody know, how I can get the MessageID or CorrelationID from an MQSeries message? - Getting the data from the message is no problem. But I also need the ID for handling reasons.

Many thanks in advance,
Christian
 
How are you getting the info at present, are you using a module?

Can you post some code?

Not everyone will have access to MQ Series so it could be a bit of a guess ...;-)

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Hi Paul,
this is an excerpt of the code:

$queue = MQSeries::Queue->new (Queue => $queue_name,
Mode => 'input');

# $message = MQSeries::Message->new;
$message = MQSeries::Message->new (MsgDesc => {format => MQFMT_STRING},
MsgID => "$msgid",
Data => "@rows");


$queue->Get(Message => $message, Sync => 1,);
print "Message:". $message->Data()."\n";
#did not work: print "MessageID: " . $message->MsgID() . "\n";
print "Message:". $message->MsgDesc("MsgId")."\n";

It doesn't complain about the 'MsgID', but returns values like this: ???@????@@@@@@@@?hv,??Öª

The message data is shown. I also had a look into the module and tried to access the hash, but this didn't work either.

I've set the MsgID / Message data with this command:

$message = MQSeries::Message->new (MsgDesc => {format => MQFMT_STRING},
MsgID => "$msgid",
Data => "@rows");

I'm using these modules:
use MQSeries;
use MQSeries::Queue;
use MQSeries::Message;

Many thanks for your help.

Cheers,
Christian
 
Looks like your MsgId is binary, you might have to unpack it...
 
Hi stevexff,
unfortunately I don't know the format, in which the data comes along. Thus, is almost impossible to find the correct template :-(
 

IBM said:
MsgId (MQBYTE24)
Message identifier.

This is a byte string that is used to distinguish one message from another. Generally, no two messages should have the same message identifier, although this is not disallowed by the queue manager. The message identifier is a permanent property of the message, and persists across restarts of the queue manager. Because the message identifier is a byte string and not a character string, the message identifier is not converted between character sets when the message flows from one queue manager to another.
In other words, it's just a 24-byte binary field. I shouldn't try to print it, unless you unpack it to hex. unless you really need to see it, just treat it as a token.
 
* for bringing back the memories, ... oh and the effort ;-)

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Hi,
just got the information from our MQ guys, that I'm not allowed to use the MsgID, but I can use the CorrelId (MQBYTE24). Can anybody of you tell me, how to retrieve the CorrelID again? I tried to do it that way:

$queue = MQSeries::Queue->new (Queue => $queue_name,
Mode => 'input');

$message = MQSeries::Message->new (MsgDesc => {format => MQFMT_STRING},
CorrelId => "$correlid",
Data => "@rows");
$queue->Get(Message => $message);
#print "Message:". $message->Data()."\n";
$correlid = pack("B24", $message->MsgDesc("CorrelId"));
print "CorrelId: $correlid\n";

but the output is emty :-(
I've set (hope so) the CorrelID using these commands:

$correlid = "CIM";
$correlid = unpack ("B24", $correlid);
#print "unpack'd: $correlid\n";
$queue = MQSeries::Queue->new (Queue => $queue_name,
Mode => 'output');

$message = MQSeries::Message->new (MsgDesc =>
{format => MQFMT_STRING},
CorrelID => "$correlid",
Data => "@rows");

$queue->Put(Message => $message);

The value in $correlid ("CIM") at least was translated to "010000110100100101001101"

Our MQ guys couldn't help me, because they only have Java skills.

Thanks a lot,
Chris
 
It's not a 24-bit binary value. It's 24 bytes. That's 192 bits...
 
Does this mean, the value is stored as a string? - But how to tanslate to a binary value? I'm not that experienced.
But regardless whether I put a 24 bit or a 24 byte value into the CorrelId, the attribute is of type Byte24. Thus it shouldn't matter? Do you have an idea on how to get tge CorrelId from the message?
 
It's been a while, but from memory you GET a message, take the msgID from it, and use it to set the correlID of the message you PUT back on the reply Q. So you shouldn't have to make them up yourself, or print them out. Just use it as an opaque token string.
 
OK, so I guess there is now way in using the CorrelId as actually intended. I think I'll then write the header on the top of the data block.

Thanks a lot for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top