【问题标题】:How to process the same message sequentially in Camel?如何在 Camel 中按顺序处理相同的消息?
【发布时间】:2015-07-19 13:21:12
【问题描述】:

我是 Camel 的新手,我正在尝试执行以下操作。

我想处理两次相同的消息。我必须先转换两条消息并处理一条消息,然后只有在成功执行第一条消息时才处理第二条消息(我有一个条件)。

我首先尝试使用多播。然后我转换每条路由中的消息。第一个(操作_DC)仅在成功时才向第二个(操作_AC)发送成功消息。第二个操作包含一个聚合,该聚合等待两条消息都超时。我只想处理来自多播的消息并丢弃另一个。

<route id="t_operation_ME">
    <from uri="direct:operation_ME" id="t.direct.aggregatedService"></from>
    <setHeader headerName="id">
        <simple>exchangeId</simple>
    </setHeader>
    <multicast parallelProcessing="true" strategyRef="defaultAggregationStrategy" stopOnException="true" onPrepareRef="cleanHeader" parallelAggregate="false" completionPredicate="">
        <to uri="direct:operation_DC"></to>
        <to uri="direct:operation_AC"></to>
    </multicast>
</route>

<route id="direct:operation_DC">
    <from uri="direct:operation_DC" />
    <log message="ENTER DC"></log>
    <to uri="xslt:{{depasse:core.transformation.xml.path}}client/t/Operation_toDC_request.xsl" id="t.dc.transform.productos" />
    <to uri="activemq:QCIn" id="t.dc.qcin.queue.send"></to>
    <log message="EXIT DC ${body}"></log>
    <choice>
        <when>
            <xpath>//Data/Status[. = 'OK']</xpath>
            <log message="SEND TO AC"></log>
            <to uri="direct:operation_AC"></to>
        </when>
    </choice>
</route>

<route id="direct:operation_AC">
    <from uri="direct:operation_AC" />
    <log message="ENTER AC"></log>
    <aggregate completionTimeout="20000" completionSize="2" discardOnCompletionTimeout="true" strategyRef="tAggregationStrategy">
        <correlationExpression>
            <simple>header.id</simple>
        </correlationExpression>
        <log message="ENTER AGG AC ${body}"></log>

        <to uri="xslt:{{depasse:core.transformation.xml.path}}client/t/Operation_toAC_request.xsl" id="t.ac.transform.productos" />
        <to uri="activemq:QCIn" id="t.ac.qcin.queue.send"></to>
        <log message="EXIT AC ${body}"></log>
    </aggregate>
    <log message="END AC\n${body}"></log>
</route>

问题是,当我记录“EXIT AC”和“END AC”时,消息是不同的。这意味着当我在服务器中正确观看该过程时,AC 客户端收到了不正确的消息。

【问题讨论】:

  • 路由 id 是 operationCDI_AC 而不是 operation_AC。对吗?
  • 你说得对。但是我更改了所有名称以便在 StackOverflow 中发布问题。我编辑了这个问题,你应该看到它就像“operation_AC”一样简单。

标签: apache-camel


【解决方案1】:

组播总是将消息的副本发送到标签之间的每个端点。如果你想在 operation_DC 成功运行后才调用路由 operation_AC,你不应该使用多播,但你应该在 operation_DC 开始时保存你的 body,例如使用属性和Camel Simple

<from uri="direct:operation_DC" />
<setProperty propertyName="body">
    <simple>${body}</simple>
</setProperty>

在调用 operation_AC 之前设置正文从头开始:

<setBody>
    <simple>${property.body}</simple>
</setBody>
<to uri="direct:operation_AC"/>

【讨论】:

    猜你喜欢
    • 2014-05-18
    • 1970-01-01
    • 2012-07-12
    • 2019-10-28
    • 1970-01-01
    • 1970-01-01
    • 2011-01-16
    • 2013-09-11
    • 2012-12-26
    相关资源
    最近更新 更多