Search code examples
javaibm-mq

Issue with context data


I'm trying to set the ApplicationIdData while sending message to a queue, using IBM MQ in java.

When I run the below code, the message is getting published to the queue as expected, but the ApplicationData received at the other receiver end is blank/empty.

int openOptions =  MQConstants.MQOO_SET_IDENTITY_CONTEXT | MQConstants.MQOO_OUTPUT | MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_INQUIRE;
queue = mqManager.accessQueue(queueName, openOptions);
int putOptions =  MQConstants.MQPMO_ASYNC_RESPONSE;;
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = putOptions;

MQMessage msg = new MQMessage();
msg.applicationIdData = "TestId";
msg.writeString(qmessage);

queue.put(msg, pmo);

I believe ApplicationIdData belongs to the Identity Context group. So, I tried using MQPMO_SET_IDENTITY_CONTEXT in the putOptions, but I keep gettin an error: "MQException: Reason 2095" and message does not even get published to the queue. Any thoughts/suggestions please?

Thank you!


Solution

  • To be able to use the MQPMO_SET_IDENTITY_CONTEXT put message option you also need to open the queue with the open option MQOO_SET_IDENTIY_CONTEXT:

    "For the MQPUT call, the queue must have been opened with the MQOO_SET_IDENTITY_CONTEXT option" from https://www.ibm.com/docs/en/ibm-mq/7.5?topic=f-options-mqlong-11

    And of course the userid you are using to send this message will need the setid authority on the queue.