如下所述: setting ReplyToQ attribute of MQMD of IBM MQ request message with Camel 我设法在Camel Route中正确地在MQMD中设置了ReplyToQ,但是我无法在同一个Route中获得响应,而IBM MQ端点(“to”)我想同时用于输出(请求)和输入(响应),因为它匹配错误的相关ID,如下所示:
在以下内容中未收到OUT消息:20000毫秒到期回复消息,其中包含相关ID:Camel-ID-MYPC-62418-1518179436629-0-5未在目的地收到:queue:/// REPLYQ。交换[ID-MYPC-62418-1518179436629-0-4]
即,响应应用程序将CorrelationID(在MQMD中)设置为MessageID(来自接收到的请求的MQMD)。如何使这种情况有效?
我尝试使用useMessageIDAsCorrelationID,但这并没有改变很多结果(不消耗响应)。另一个尝试是将请求的MessageID设置为某个固定值(这不是最终解决方案),但我甚至不能这样做。我补充说:
<setHeader headerName="JMSMessageID" id="_setHeader2">
<constant>abcdefg</constant>
</setHeader>
<setHeader headerName="JMSCorrelationID" id="_setHeader3">
<constant>abcdefg</constant>
</setHeader>
但是这只设置了CorrelationID,我仍然会得到这样的东西:
在以下内容中未收到OUT消息:20000毫秒到期回复消息,其中带有correlationID:目标上未收到abcdefg:queue:/// REPLYQ。交换[ID-MYPC-65151-1518190285422-0-3]
完整路线定义:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean class="org.apache.camel.component.jms.JmsComponent" id="websphere">
<property name="connectionFactory">
<bean class="com.ibm.mq.jms.MQConnectionFactory">
<property name="transportType" value="1"/>
<property name="hostName" value="hostname"/>
<property name="port" value="port"/>
<property name="queueManager" value="qmgr_name"/>
<property name="channel" value="channel_name"/>
</bean>
</property>
</bean>
<!-- Define a traditional camel context here -->
<camelContext id="camel" useBreadcrumb="false" xmlns="http://camel.apache.org/schema/spring">
<route id="simple-route">
<from id="request-file" uri="file://C:/mqdocuments/?fileName=request.txt"/>
<log id="route-log" message=">>> ${body}"/>
<setHeader headerName="CamelJmsDestinationName" id="_setHeader1">
<constant>queue://QM_TEST/INPUTQ?targetClient=1&mdWriteEnabled=true&mdReadEnabled=true</constant>
</setHeader>
<setHeader headerName="JMSMessageID" id="_setHeader2">
<constant>abcdefg</constant>
</setHeader>
<setHeader headerName="JMSCorrelationID" id="_setHeader3">
<constant>abcdefg</constant>
</setHeader>
<to id="_to1" pattern="InOut" uri="websphere:queue:SYSTEM.DEFAULT.LOCAL.QUEUE?replyTo=REPLYQ"/>
</route>
</camelContext>
</beans>
答案 0 :(得分:1)
好的,这个简单的代码实际上就像这里解释的那样:
http://camel.apache.org/correlation-identifier.html
<route id="simple-route">
<from id="request-file" uri="file://C:/mqdocuments/?fileName=request464.txt"/>
<log id="route-log-request" message="request: ${body}"/>
<setHeader headerName="CamelJmsDestinationName" id="_setHeader1">
<constant>queue://QM_TEST/INPUTQ?targetClient=1</constant>
</setHeader>
<to id="_to1" pattern="InOut" uri="websphere:queue:SYSTEM.DEFAULT.LOCAL.QUEUE?useMessageIDAsCorrelationID=true&replyTo=REPLYQ"/>
<log id="route-log-response" message="response: ${body}"/>
</route>
它打印出整齐的响应体到控制台输出。
我不知道为什么我在第一次尝试它时不会起作用。因此,总结这两个问题,问题是在队列的uri中使用useMessageIDAsCorrelationID和replyTo参数,以及<to>
端点的pattern =“InOut”参数。