【发布时间】: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