So, I have a message that I'm sending over an IBM mq queue and I would like to give it a customised MessageID. I've implemented DestinationResolver with the below properties in order to enable MQMD properties:
queue.setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);
I'm able to set the JMS_IBM_MQMD_ApplIdentityData header but I'm struggling to set the JMS_IBM_MQMD_MsgId header.
This is the MessageID I'm trying to set: String messageID = "ID:TESTYTEST";
If I set JMS_IBM_MQMD_MsgId like this:
message.setAttribute("JMS_IBM_MQMD_MsgId", messageID.getBytes());
then I get the below error
org.apache.camel.component.jms.JmsBinding - Ignoring non primitive header: JMS_IBM_MQMD_MsgId of class: [B
However, if I set JMS_IBM_MQMD_MsgId like this:
message.setAttribute("JMS_IBM_MQMD_MsgId", messageID);
then I get the below error
com.ibm.msg.client.jms.DetailedMessageFormatException: JMSCC0051: The property 'JMS_IBM_MQMD_MsgId' should be set using type '[B', not 'java.lang.String'. JMS_IBM properties may only be set using a specific variable type. Correct application code to use the required variable type when setting this JMS_IBM property.
First of all - MessageId is array of 24 bytes. And that is your error. You are trying to push String in byte array - [B. Once you fix this error, you will still not be able to successfully set MessageId. As MQ will completely ignore any value set by message producer, and it will always override your MessageId with arbitary value.
Blame JMS API. It is little bit idiotic and it doesn't make distiction between end user interface and messaging driver programmer interface. There is more than one setter on javax.jms.Message which is not inteded to be used by everday Joe.
So what can you do about it? For start you can use different field: Message Type and CorrelationID headers are inteded to be used by end users. CorrelationID shares the same byte[24] design, and it is functionally identical to MessageID. Usually, CorrelationID is shared between couple different messages which are "correleated", thus the name. You can also add arbitary header to message.
But if you really really need to know MessageID of sent message - because of audit, correlation or something else - you can first send message, and the read MessageID field back. It will contain generated value.