47.21. 在目的地上设置 JMS 供应商选项
某些 JMS 提供程序(如 IBM 的 WebSphere MQ)需要在 JMS 目的地上设置选项。例如,您可能需要指定 targetClient 选项。由于 targetClient 是 WebSphere MQ 选项而不是 Camel URI 选项,您需要在 JMS 目的地名称上设置它,如下所示:
// ...
.setHeader("CamelJmsDestinationName", constant("queue:///MY_QUEUE?targetClient=1"))
.to("wmq:queue:MY_QUEUE?useMessageIDAsCorrelationID=true");
有些版本的 WMQ 不会在目标名称上接受这个选项,您会看到如下例外:
com.ibm.msg.client.jms.DetailedJMSException: JMSCC0005: The specified
value 'MY_QUEUE?targetClient=1' is not allowed for
'XMSC_DESTINATION_NAME'
一个临时解决方案是使用自定义 DestinationResolver:
JmsComponent wmq = new JmsComponent(connectionFactory);
wmq.setDestinationResolver(new DestinationResolver() {
public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain) throws JMSException {
MQQueueSession wmqSession = (MQQueueSession) session;
return wmqSession.createQueue("queue:///" + destinationName + "?targetClient=1");
}
});