Recipient List camel并行

图例

image

官网地址

说明
Recipient List 和 Muticas 很类似,都是把消息复制成多份,然后执行
SpringXML事例
<route>
  <from uri="direct:a" />
  <!-- use comma as a delimiter for String based values -->
  <recipientList delimiter=",">
    <header>myHeader</header>
  </recipientList>
</route>

其中delimiter 表示用来作为myHeader分割的正则表达式,上面的意思就是说,当执行到
direct:a的时候,把myHeader使用delimiter分割出来的字符串,作为下面执行的路由地址

java事例
from("direct:a").recipientList(header("myHeader").tokenize(","));

使用tokenize来分割路由uri


from("direct:a").recipientList(header("myHeader"), ",");
Sending to multiple recipients in parallel 并行处理
recipientList支持并行处理
  • java事例

    from("direct:a").recipientList(header("myHeader")).parallelProcessing();
  • Spriong事例

    <route>
        <from uri="direct:a"/>
        <recipientList parallelProcessing="true">
            <header>myHeader</header>
        </recipientList>
    </route>
stopOnException 异常停止
recipientList支持配置出异常是否停止参数
  • java事例

    from("direct:a").recipientList(header("myHeader")).stopOnException();
  • SpringXML事例

    <route>
        <from uri="direct:a"/>
        <recipientList stopOnException="true">
            <header>myHeader</header>
        </recipientList>
    </route>

parallelProcessing 可以和 stopOnException 并用


ignoreInvalidEndpoints 忽略错误的uri地址
  • java事例

    from("direct:a").recipientList(header("myHeader")).ignoreInvalidEndpoints();
  • SpringXML事例

    <route>
        <from uri="direct:a"/>
        <recipientList ignoreInvalidEndpoints="true">
            <header>myHeader</header>
        </recipientList>
    </route>
AggregationStrategy 聚合策略
你可以在recipientList之后进行聚合,一般用的比较少,它的用处是,如果您正在
使用请求应答消息接收者可以聚合的回复,默认情况下,camel会使用最后一次的响应作为聚合消息。
  • java事例

    from("direct:a")
        .recipientList(header("myHeader")).aggregationStrategy(new MyOwnAggregationStrategy())
        .to("direct:b");

    MyOwnAggregationStrategy需要集成一个借口并实现aggregate方法,如下:

@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
    String uri = newExchange.getProperty(Exchange.RECIPIENT_LIST_ENDPOINT, String.class);
    ...
}

在上面的方法中可以自定义如何出来并行路由响应的结果。
- SpringXML事例

```
<route>
    <from uri="direct:a"/>
    <recipientList strategyRef="myStrategy">
        <header>myHeader</header>
    </recipientList>
    <to uri="direct:b"/>
</route>

<bean id="myStrategy" class="com.mycompany.MyOwnAggregationStrategy"/>
```
timeout 超时设置

mutilcas并行可设置总的一个超时

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值