【问题标题】:Proper use of Camel Aggregator "to" URIs正确使用骆驼聚合器“到”URI
【发布时间】:2014-01-30 13:30:55
【问题描述】:

我有一条路线,希望 Camel 访问以下 bean:

  1. 首先,loggingBean
  2. 第二个,aggregator,它等待一定数量的消息在其上聚合
  3. 到达聚合器的completionSize 后 (3),继续转到 #4
  4. 第三,processorBean
  5. 第四个/最后一个,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 放在 &lt;aggregate&gt; 元素中:

<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&lt;aggregate&gt; 元素内部与在它外部有什么区别?

【问题讨论】:

    标签: java apache-camel aggregation


    【解决方案1】:

    第二个例子是正确的。

    <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 在“外部”&lt;aggregate&gt;,它将针对来自direct:starter 的每条消息执行 - 这不是您想要的 ;)

    【讨论】:

    • 我们如何使用 Java DSL 表达同样的事情? aggregate().to() 是否符合我的预期,即只向命名路由发送一次聚合交换?
    • 对,aggregate(new MyStrategy()).completionSize(3).to("bean:xyz") 之类的内容是等价的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-14
    • 1970-01-01
    • 1970-01-01
    • 2021-08-23
    • 2016-10-30
    • 2015-07-07
    相关资源
    最近更新 更多