WMQ C ++ Get request message id and set its correlation id for response

I am having a problem getting the post id and setting it on the response correlation id.

Here's a piece of code:

MQBYTE msgID;

request_msg.messageId().copyOut(msgID, MQ_MSG_ID_LENGTH, 0);
response_msg.setCorrelationId(msgID);

      

when i checked the response correlation id the correlation id is 0.

How can I copy / get the Request Id message and put it on the response correlation ID?

Thanks in advance.:)

+3


source to share


1 answer


The Infocenter Binary String Manipulation page in C ++ shows the data types used like ImqBinary

and MQBYTE24

. As Shashi points out in the comments, it MQBYTE

is one byte and cannot contain a 24 byte message ID. See the page above for a link example:

#include <imqi.hpp> // C++ classes

ImqMessage message ;
ImqBinary id, correlationId ;
MQBYTE24 byteId ;

correlationId.set( byteId, sizeof( byteId ) ); // Set.
id = message.id( );                            // Assign.
if ( correlationId == id ) {                   // Compare.
  ...

      

One of the tools to diagnose such problems is the very useful SupportPac MA0W , which is an API exit. It can show you the exact contents of the structures passed to MQ before and after the API call. It is very often seen that the expected (in this case, copying MQMD.MsgID

to is MQMD.CorrelID

not what actually happened. In this case, I believe that a trace like MA0W would show that it msgID

was accurately transferred from the application to MQ, but consisted only of one character.

UPDATE
OP asks:

Variable id

- it ImqBinary

and message

- ImqMessage

the object of what I know id

is not a member ImqMessage

, like messageId

, correlationId

, groupId

, and so on, so that message.id()

gave it value on id

?

You agree that it id

is a declared variable of type ImqBinary

, not a member of the class ImqMessage

. See the Infocenter page for the ImqBinary C ++ class , which explains that:

This class encapsulates a binary byte array that can be used for ImqMessage accounting token, correlation ID, and message ID values. This makes it easy to assign, copy and compare.



The purpose of the class ImqBinary

is to provide a variable type to encapsulate a byte array with overloaded methods so that "normal" variable manipulations work as expected. Instead of copying a byte array one byte at a time, it can be LVAL

either RVAL

in the job. Instead of comparing an array of bytes at a time, you can simply use comparison operators such as ==

.

So, if your code was modified to use the example, it might look like this:

#include <imqi.hpp> // C++ classes

ImqMessage request_msg, response_msg ;
ImqBinary id ;

id = request_msg.id( );
response_msg.setCorrelationId(id);

      

However, I'm not sure if you even need an intermediate variable. You might be able to assign a correlation id using the getter call output for the message id from the original message. Something like....

response_msg.setCorrelationId( request_msg.id( ) );

      

... can do it. I am no longer coding C or C ++, so I probably misunderstood the syntax or did not do it as elegantly as it could have been coded, but you should get the idea.

+4


source







All Articles