How to make Camel pattern=“InOut” work with IBM MQ

别说谁变了你拦得住时间么 提交于 2019-12-11 05:18:22

问题


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:

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]

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

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>

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

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]

Complete route definition:

<?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:


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>

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.



来源:https://stackoverflow.com/questions/48708716/how-to-make-camel-pattern-inout-work-with-ibm-mq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!