Apache Camel - IBM MQ integration

2019-03-03 00:44发布

I have a Apache camel (version 2.18) project that sends a file to my partner's IBM MQ server by IBM MQ client. However, my partner uses the messageId as the filename, thus, we have to set specific filename tomessageId.

My question is how we can change the messageId?

I tried to add JMS_IBM_MQMD_MsgId or MsgId or modify the JMSMessageId in JMS header before I send the file to the IBM MQ server, but it doesn't work. Do you have any solution?

Here is the code in spring file. For example, before we send JMS to my partner's server. We set the below key/value to JMS header:

exchange.getIn().setHeader("JMS_IBM_MQMD_MsgId",MsgExtFileName().getBytes())
exchange.getIn().setHeader("JMS_IBM_Format", MQC.MQFMT_STRING)

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-03-03 01:12

IBM MQ v8 Knowledge center documents how to set MQMD properties with IBM MQ Classes for JMS in the page "Reading and writing the message descriptor from an IBM MQ classes for JMS application"

You must set the Destination object property WMQ_MQMD_WRITE_ENABLED to true for the setting of MQMD properties to have any effect. You can then use the property setting methods of the message (for example setStringProperty) to assign values to the MQMD fields. All MQMD fields are exposed except StrucId and Version; BackoutCount can be read but not written to.

// Enable MQMD write
dest.setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);

The IBM MQ v8 Knowledge center page "JMS message object properties" documents the properties that can set be set.


I am a IBM MQ admin and not versed in Apache Camel, but I found this StackOverflow post "How to set ApplicationIdData using MQQueueConnectionFactory?" helpful along with the Apache Camel Documentation on "Simple Expression Language"

For example to set a header as a boolean type you can do:

.setHeader("cool", simple("true", Boolean.class))

Based on the above information you just need to add one additional line to allow you to set the JMS_IBM_MQMD_MsgId peroperty:

exchange.getIn().setHeader("mdWriteEnabled", simple("true", Boolean.class))
exchange.getIn().setHeader("JMS_IBM_MQMD_MsgId",MsgExtFileName().getBytes())
exchange.getIn().setHeader("JMS_IBM_Format", MQC.MQFMT_STRING)

NOTE based on some other info I found the setHeader above may not be correct and you may need to append it to the end of your Queue destination URI:

queue:///QueueName?mdWriteEnabled=true

Note that the messageId in the IBM MQ MQMD is represented as 24 bytes. This not not converted when passed from platform to platform, if you are using normal alpha numeric characters this should not be a problem even going from UTF-8 to ASCII since the byte values are the same, but it is something to be aware of.

For more information on messageId and character sets reference these two StackOverflow answers:

Get MQ messageId in string format
CCSID on MQ Managers on different platforms

查看更多
登录 后发表回答