代码之家  ›  专栏  ›  技术社区  ›  hdjur_jcv

如何使Camel模式=“InOut”与IBM MQ一起工作

  •  1
  • hdjur_jcv  · 技术社区  · 8 年前

    如下所述: setting ReplyToQ attribute of MQMD of IBM MQ request message with Camel 我在驼峰路由中成功地在MQMD中正确设置了ReplyToQ of request,但我无法在同一路由中获得响应,因为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毫秒到期回复消息,相关ID: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&amp;mdWriteEnabled=true&amp;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>
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   hdjur_jcv    8 年前

    好的,这个简单的代码实际上是按照这里的解释工作的:

    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&amp;replyTo=REPLYQ"/>
            <log id="route-log-response" message="response: ${body}"/>
        </route>
    

    它将响应体整齐地打印到控制台输出。 我不知道为什么当我第一次尝试它时,我会觉得它不起作用。因此,为了总结这两个问题,关键在于在队列的uri中使用useMessageIDAsCorrelationID和replyTo参数,以及 <to> 端点。