我有一条路线,我希望骆驼去拜访以下豆类:


首先,loggingBean
其次,一个aggregator等待一定数量的消息聚集在其上
达到聚合器的completionSize(3)后,继续执行第4个
第三,processorBean
第四/倒数第二个,finalizerBean


这是我的路线:

<route id="my-camel-route">
    <from uri="direct:starter" />

    <to uri="bean:loggingBean?method=shutdown" />

    <aggregate strategyRef="myAggregationStrategy" completionSize="3">
        <correlationExpression>
            <simple>${header.id} == 1</simple>
        </correlationExpression>
        <to uri="bean:processorBean?method=process" />
    </aggregate>

    <to uri="bean:finalizerBean?method=shutdown" />
</route>


我的问题:是否需要将finalizerBean放置在<aggregate>元素内,如下所示:

<aggregate strategyRef="myAggregationStrategy" completionSize="3">
    <correlationExpression>
        <simple>${header.id} == 1</simple>
    </correlationExpression>
    <to uri="bean:processorBean?method=process" />
    <to uri="bean:finalizerBean?method=shutdown" />
</aggregate>


基本上,我想知道我当前的处理方式是否会提示Camel将消息发送到聚合器,然后再将其发送到finalizerBean(本质上是绕过聚合器)。就我而言,我希望它聚合直到completionSize为3,然后将聚合的交换发送到processorBean,最后是finalizerBean

还是我配置正确? finalizerBean位于<aggregate>元素内部与位于元素外部之间有什么区别?

最佳答案

第二个例子是正确的。

<aggregate strategyRef="myAggregationStrategy" completionSize="3">
    <correlationExpression>
        <simple>${header.id} == 1</simple>
    </correlationExpression>
    <to uri="bean:processorBean?method=process" />
    <to uri="bean:finalizerBean?method=shutdown" />
</aggregate>


如果finalizerBean在<aggregate>之外,它将针对来自direct:starter的每条消息执行-这不是您想要的;)

09-27 10:08