Apache camel 如何制作驼峰图案=";InOut“;使用IBM MQ
如下所述: 我在驼峰路由中成功地在MQMD of request中正确地设置了ReplyToQ,但我无法在同一路由中获得响应,因为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设置为某个固定值(这不是最终的解决方案),但我甚至不能这样做。我补充说:Apache camel 如何制作驼峰图案=";InOut“;使用IBM MQ,apache-camel,Apache Camel,如下所述: 我在驼峰路由中成功地在MQMD of request中正确地设置了ReplyToQ,但我无法在同一路由中获得响应,因为IBM MQ端点(“to”)我希望用于输出(请求)和输入(响应),因为它与错误的相关ID相匹配,如下所示: 未在以下时间内收到OUT消息:20000毫秒到期回复消息,相关ID:Camel-ID-MYPC-62418-1518179436629-0-5未在目标上收到:queue:///REPLYQ. 交易所[ID-MYPC-62418-1518179436629-0-4
<setHeader headerName="JMSMessageID" id="_setHeader2">
<constant>abcdefg</constant>
</setHeader>
<setHeader headerName="JMSCorrelationID" id="_setHeader3">
<constant>abcdefg</constant>
</setHeader>
abcdefg
abcdefg
但这只设置了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>
queue://QM_TEST/INPUTQ?targetClient=1&mdWriteEnabled=为真&;mdReadEnabled=true
abcdefg
abcdefg
好的,这个简单的代码实际上按照这里的解释工作:
queue://QM_TEST/INPUTQ?targetClient=1
它将响应体打印到控制台输出。
我不知道为什么当我第一次尝试它时,我会觉得它不起作用。因此,总结这两个问题,关键在于在队列的uri中使用useMessageIDAsCorrelationID和replyTo参数,以及
端点的pattern=“InOut”参数。顺便说一句,last setHeader标记在请求消息的MQMD中正确地设置了CorrelationID,但这没有多大帮助,由于响应应用程序不使用请求消息的该属性。如果要在响应服务中实现,我希望useMessageIDAsCorrelationID会很有用,它必须将响应的CorrelationID设置为接收到的请求的MessageID,这里的情况并非如此。您可以添加完整的路由定义吗?您在MQMD头中看到了正确的replyto属性吗?@thuri在这里,我用整个路由定义更新了问题。
<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>