【问题标题】:How to configure Request Reply from 2 Different Routes in Apache Camel?如何在 Apache Camel 中配置来自 2 个不同路由的请求回复?
【发布时间】:2014-06-11 11:43:39
【问题描述】:

目前我正在使用 apache camel。在我的应用程序中,我有 2 条路线。

第一个路由包含HTTP作为输入、一些进程和WMQ(这个WMQ只用于写)

在第二条路线上,我有 WMQ(用于只读)用于 from 标记和一些映射过程。

我想要做的是将第二条路由上的 WMQ 的响应发送到第一条路由上的 HTTP。

怎么做?

这是我目前的配置。

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" default-init-method="init" xmlns:util="http://www.springframework.org/schema/util" xmlns:osgi="http://www.springframework.org/schema/osgi" xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xs http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd http://www.springframework.org/schema/osgi  http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <import resource="classpath:/META-INF/spring/components.xml"/>

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">

        <dataFormats>
            <xmljson id="xmljson" forceTopLevelObject="true" skipNamespaces="true" removeNamespacePrefixes="true"/>
        </dataFormats>

        <route>
            <from uri="jetty:http://localhost:8888/uebermittleAusweisdaten"/>
            <process ref="TransformToXML"/>
            <to uri ="xslt:soap-template.xsl"/>
            <setHeader headerName="CamelJmsDestinationName">
                <constant>queue:///Queue.w?targetClient=1</constant>    
            </setHeader>
            <setHeader headerName="JMS_IBM_Character_Set">
                <constant>ISO8859_1</constant>    
            </setHeader>
            <to uri="jms:queue:Queue.w"/>
            <inOut uri="mock:result"/>
        </route>
        <route>
            <from uri="jms:queue:queue.r"/>
            <marshal ref="xmljson"/>
            <setHeader headerName="CamelJmsDestinationName">
                <constant>mock:result</constant>    
            </setHeader>
            <to uri="stream:out"/>
        </route>

    </camelContext>

</beans>

提前致谢。

【问题讨论】:

    标签: http request apache-camel ibm-mq reply


    【解决方案1】:

    使用InOut 模式:

    <to uri="jms:queue:LSMH.ZKSEAP.SERVICEBUS" pattern="InOut" />
    

    使用InOut,Camel 会将回复发送回JMSReplyTo 队列,请参阅Camel docs 了解更多信息。

    一个简单的设置如下所示:

    <route>
        <from uri="direct:start" />
        <to uri="jms:myQueue" pattern="InOut" />
        <log message="Received body in sending route: ${body}" />
    </route>
    <route>
        <from uri="jms:myQueue" />
        <setBody><simple>${body}, World!</simple></setBody>
    </route>
    

    Hello 发送到direct:start 会导致以下日志消息:

    Received body in sending route: Hello, World!
    

    【讨论】:

    • 但是,就我而言,第一条路线中的 mq 与第二条流程中的 mq 不同。正如我在我的问题中发布的那样,第一个队列(LSMH.ZKSEAP.SERVICEBUS)仅用于写入,第二个队列(ZKSEAP.LSMH.SERVICEBUS)仅用于读取。
    • @pokopang 在您已经发送给jms:queue:LSMH.ZKSEAP.SERVICEBUS 的消息旁边使用InOut 模式向jms:queue:ZKSEAP.LSMH.SERVICEBUS 发送第二条消息(也许您也应该为您的JMS 队列选择更好的名称...... .)
    • 我不能这样做,因为队列进程上有SOAP操作,结果会有所不同。我的意思是,我将请求写入 jms:queue:LSMH.ZKSEAP.SERVICEBUS,然后当我收到响应时,我将从 jms:queue:ZKSEAP.LSMH.SERVICEBUS 中读取它。这就是为什么,如果我按照你说的那样做,那么我得到的是请求消息,而不是响应消息。
    • @pokopang 我猜你必须重构你的路线并在需要反馈时使用InOut
    • 如何重构?你能给我举个例子吗?谢谢
    猜你喜欢
    • 2014-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    • 2014-08-05
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    相关资源
    最近更新 更多