【发布时间】:2018-02-10 01:16:07
【问题描述】:
我有一个使用 apache-camel 解决方案的应用程序,想通过 jms 向 Websphere MQ 服务器发送消息,将 jms 属性 JMS_IBM_MQMD_MsgId 转换为 MQMD 字段 MQMD.MsgId,以便我通过骆驼在消息上设置此值
exchange.getIn().setHeader(WMQConstants.JMS_IBM_MQMD_MSGID, "XXXXXXXXXXXXXXXXXXXXXXXX".getBytes());
根据Apache Camel - IBM MQ integration,似乎我们需要在目标对象上设置另一个属性。参考http://camel.apache.org/jms.html上的Setting JMS Provider Options on the Destination,我为camel jms组件提供了一个自定义的DestinationResolver,为目标对象设置mdWriteEnabled,mdReadEnabled。
<bean id="ibmMQServer01" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="ibmMQCredentialConnectionFactory01" />
<property name="destinationResolver" ref="wmqDestinationResolver" />
</bean>
和
public class WMQDestinationResolver implements DestinationResolver {
@Override
public Destination resolveDestinationName(Session session, String destinationName,
boolean pubSubDomain) throws JMSException {
MQSession mqSession = (MQSession) session;
MQQueue queue = (MQQueue) mqSession.createQueue("queue:///" + destinationName);
queue.setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);
queue.setBooleanProperty(WMQConstants.WMQ_MQMD_READ_ENABLED, true);
queue.setIntProperty(WMQConstants.WMQ_MQMD_MESSAGE_CONTEXT, WMQConstants.WMQ_MDCTX_SET_ALL_CONTEXT);
return queue;
}
}
我可以在接收器上获得JMS_IBM_MQMD_MsgId,同时设置mdReadEnabled 等于真。但是,mdWriteEnabled 似乎对我不起作用,我得到了 JMS_IBM_MQMD_MsgId 作为意外值 AMQ CS.QA.CBSA.Q�Y�b(从 byte[] 解析,共 24 个字节)。
接收到的JMSMessageID是ID:414d512043532e51412e434253412e511987055902cc6222,可以解析成上面乱七八糟的字符串。
【问题讨论】:
标签: apache-camel jms ibm-mq