1

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.

1 Answers1

1

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.

JoshMc
  • 10,239
  • 2
  • 19
  • 38
Talijanac
  • 1,087
  • 9
  • 20
  • Hi@JoshMc thanks so much for this. You're correct: I'm able to modify the code to set the MessageId to an array of 24 bytes but it won't make a difference because I'm still unable to set it. I'm already making use of the CorrelationID field and we have a requirement to specifically set the MessageID when sending out a message. Is it possible to set this property using IBM mq libraries perhaps? – VerseBeCoding Apr 05 '23 at 20:25
  • No. Intention of MessageID is to track individual message, which would not be possible to do if user was able to override its value. You can use other user modifidable fields - as type, or you can add own property. For example: message.setStringProperty("MyID", hexEncodedBytesHere); – Talijanac Apr 07 '23 at 10:16