如何制作骆驼图案=“InOut"使用 IBM MQ [英] How to make Camel pattern="InOut" work with IBM MQ

查看:19
本文介绍了如何制作骆驼图案=“InOut"使用 IBM MQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如此处所述:使用 Camel 设置 IBM MQ 请求消息的 MQMD 的 ReplyToQ 属性我设法在 Camel Route 中正确设置了请求的 MQMD 中的 ReplyToQ,但是我无法在同一个路由中获得响应,我想使用 IBM MQ 端点(to")来输出(请求)对于输入(响应),因为它匹配了错误的关联 ID,如下所示:

As described here: setting ReplyToQ attribute of MQMD of IBM MQ request message with Camel I managed to set ReplyToQ in MQMD of request properly in Camel Route, but I can't get the response in the same Route, with the IBM MQ Endpoint ("to") that I would like to use both for output (of request) and for input (of response), because it is matching wrong Correlation ID, like this:

未收到 OUT 消息:20000 毫秒到期回复消息,相关 ID:Camel-ID-MYPC-62418-1518179436629-0-5 未在目的地收到:queue:///REPLYQ.交易所[ID-MYPC-62418-1518179436629-0-4]

The OUT message was not received within: 20000 millis due reply message with correlationID: Camel-ID-MYPC-62418-1518179436629-0-5 not received on destination: queue:///REPLYQ. Exchange[ID-MYPC-62418-1518179436629-0-4]

即,响应应用程序将 CorrelationID(在 MQMD 中)设置为 MessageID(来自收到请求的 MQMD).如何使这个场景起作用?

Namely, responding application sets CorrelationID (in MQMD) to the MessageID (from MQMD of the received request). How to make this scenario work?

我尝试过使用 useMessageIDAsCorrelationID,但这并没有改变多少结果(不消耗响应).另一种尝试是将请求的 MessageID 设置为某个固定值(这不是最终解决方案),但我什至不能这样做.我添加了这个:

I tried with useMessageIDAsCorrelationID, but this doesn't change much the result (responses are not consumed). Another try was to set MessageID of request to some fixed value (that would not be final solution), but I can't even do that. I added this:

        <setHeader headerName="JMSMessageID" id="_setHeader2">
            <constant>abcdefg</constant>
        </setHeader>
        <setHeader headerName="JMSCorrelationID" id="_setHeader3">
            <constant>abcdefg</constant>
        </setHeader>

但这只设置了 CorrelationID,我仍然得到这样的东西:

but this only sets CorrelationID, and I still get such things:

未收到 OUT 消息:20000 毫秒到期回复消息,相关 ID:abcdefg 未在目的地接收:queue:///REPLYQ.交易所[ID-MYPC-65151-1518190285422-0-3]

The OUT message was not received within: 20000 millis due reply message with correlationID: abcdefg not received on destination: queue:///REPLYQ. Exchange[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>

推荐答案

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

OK, this simple code actually works as explained here:

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> 端点的 pattern="InOut" 参数.

It prints out neatly response body to console output. I don't know why I was under impression that it doesn't work when I first tried it. So, to summarize both questions, the catch is in using useMessageIDAsCorrelationID and replyTo parameters in uri of a queue, as well as pattern="InOut" parameter of <to> endpoint.

这篇关于如何制作骆驼图案=“InOut"使用 IBM MQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆