图例
说明
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并行可设置总的一个超时