【问题标题】:Camel AggregationStrategy behaving unexpectedlyCamel AggregationStrategy 行为异常
【发布时间】:2013-12-17 20:15:05
【问题描述】:

我有一种情况,我想将数据传递到 Aggregator,但我不希望聚合器在收到来自 3 个不同路由的消息之前执行任何操作:

<route id="route-1">
    <from uri="direct:fizz" />

    <to uri="bean:bean1?method=process" />

    <setHeader headerName="id">
        <constant>1</constant>
    </setHeader>

    <to uri="direct:aggregator" />
</route>

<route id="route-2">
    <from uri="direct:buzz" />

    <to uri="bean:bean2?method=process" />

    <setHeader headerName="id">
        <constant>2</constant>
    </setHeader>

    <to uri="direct:aggregator" />
</route>

<route id="route-3">
    <from uri="direct:foo" />

    <to uri="bean:bean3?method=process" />

    <setHeader headerName="id">
        <constant>3</constant>
    </setHeader>

    <to uri="direct:aggregator" />
</route>

<route id="aggregator-route">
    <from uri="direct:aggregator" />

    <aggregate strategyRef="myAggregationStrategy" completionSize="1">
        <correlationExpression>
            <simple>header.id</simple>
        </correlationExpression>
        <to uri="bean:lastBean?method=process" />
    </aggregate>
</route>

这种配置方式,当聚合器的completionSize 设置为1 或2 时,聚合的Exchange 被路由到我的lastBean。但是,如果我将 completionSize 设置为 3,出于某种原因,lastBean#process 永远不会被调用。

确定我在这里错误地使用了header.id 和聚合器。在correlationExpression 中,我只需要确保我们有来自 3 条路线中的每条路线的 1 条消息。

所以我的问题是:我需要做什么才能让我的聚合器“等待”直到它收到来自 route-1 的 1 条消息、来自 route-2 的 1 条消息和来自 route-3 的 1 条消息?强>

【问题讨论】:

  • 一个好主意是多研究 EIP 以了解它是如何工作的。 EIP 书和 Camel in Action 第 8 章广泛涵盖了此 EIP。还有一些文档:camel.apache.org/aggregator2.html

标签: java apache-camel soa aggregation


【解决方案1】:

如果您要关联来自三个路由的消息,则需要有一种方法让它们在到达聚合路由时都具有匹配的 header.id 值。

在您的示例中,每条路由都设置了不同的 id 值,因此不会有匹配项。如果您在每条路由中将 id 值设置为“1”,我认为它会开始按预期工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    • 2016-06-24
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多