简体   繁体   English

Apache Camel - IBM MQ 集成

[英]Apache Camel - IBM MQ integration

I have a Apache camel (version 2.18) project that sends a file to my partner's IBM MQ server by IBM MQ client.我有一个 Apache camel(2.18 版)项目,它通过 IBM MQ 客户端将文件发送到我合作伙伴的 IBM MQ 服务器。 However, my partner uses the messageId as the filename, thus, we have to set specific filename to messageId .但是,我的合作伙伴使用messageId作为文件名,因此,我们必须将特定文件名设置为messageId

My question is how we can change the messageId ?我的问题是我们如何更改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.在将文件发送到 IBM MQ 服务器之前,我尝试添加JMS_IBM_MQMD_MsgIdMsgId或修改 JMS 标头中的JMSMessageId ,但它不起作用。 Do you have any solution?你有什么解决办法吗?

Here is the code in spring file.这是spring文件中的代码。 For example, before we send JMS to my partner's server.例如,在我们将 JMS 发送到我合作伙伴的服务器之前。 We set the below key/value to JMS header:我们将以下键/值设置为 JMS 标头:

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

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 " IBM MQ v8 知识中心在“ 从 IBM MQ 类为 JMS 应用程序读取和写入消息描述符”页面中记录了如何使用 IBM MQ Classes for JMS 设置 MQMD 属性

You must set the Destination object property WMQ_MQMD_WRITE_ENABLED to true for the setting of MQMD properties to have any effect.您必须将 Destination 对象属性 WMQ_MQMD_WRITE_ENABLED 设置为 true 以使 MQMD 属性的设置生效。 You can then use the property setting methods of the message (for example setStringProperty) to assign values to the MQMD fields.然后,您可以使用消息的属性设置方法(例如 setStringProperty)为 MQMD 字段赋值。 All MQMD fields are exposed except StrucId and Version;除 StrucId 和 Version 外,所有 MQMD 字段都公开; BackoutCount can be read but not written to. BackoutCount 可以读取但不能写入。

 // 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. IBM MQ v8 知识中心页面“ JMS 消息对象属性”记录了可以设置的属性。


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 "我是 IBM MQ 管理员,不精通 Apache Camel,但我发现这篇 StackOverflow 帖子“ 如何使用 MQQueueConnectionFactory 设置 ApplicationIdData? ”以及“简单表达式语言”上的 Apache Camel 文档很有帮助

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:根据以上信息,您只需要添加一行以允许您设置 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:注意基于一些其他信息,我发现上面的 setHeader 可能不正确,您可能需要将其附加到队列目标 URI 的末尾:

queue:///QueueName?mdWriteEnabled=true

Note that the messageId in the IBM MQ MQMD is represented as 24 bytes.请注意,IBM MQ MQMD 中的 messageId 表示为 24 个字节。 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.这在从平台传递到平台时不会转换,如果您使用普通的字母数字字符,即使从 UTF-8 到 ASCII 也不应该是一个问题,因为字节值是相同的,但这是需要注意的。

For more information on messageId and character sets reference these two StackOverflow answers:有关 messageId 和字符集的更多信息,请参考这两个 StackOverflow 答案:

Get MQ messageId in string format 以字符串格式获取MQ messageId
CCSID on MQ Managers on different platforms 不同平台上 MQ 管理器上的 CCSID

We are faced with the same problem: we have to generate ID by some rule and set it to MQMD MsgID.我们面临同样的问题:我们必须通过某种规则生成 ID 并将其设置为 MQMD MsgID。 This code do this:此代码执行此操作:

exchange.getIn().setHeader("CamelJmsDestinationName", "queue:///QueueName?mdWriteEnabled=true");
exchange.getIn().setHeader("JMS_IBM_MQMD_MsgId", "123456789012345678901234".getBytes());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM