我们在Camel中定义了一个具有拆分和聚合功能的路由,但是不能在聚合器之后将异常传播回分割。即使遇到异常,导致拆分的原因是什么
以下是无效的代码
from("direct:MyRoute")
.routeId("MyRouteID")
.split().tokenize("\n", 1)
.streaming().stopOnException()
.choice()
.when(simple("${property.CamelSplitIndex} > 0"))
.unmarshal(domainDataFormat)
.choice()
.when(simple("${property.CamelSplitComplete}"))
.process(
new Processor()
{
@Override
public void process(Exchange exchange) throws Exception
{
exchange.getIn().getHeaders().put(Exchange.AGGREGATION_COMPLETE_ALL_GROUPS_INCLUSIVE, true);
}
}
)
.end()
.aggregate(myAggregationStrategy).constant(true) //if i comment this line split will be stop on exception
.threads().executorService(executorService)
.process(myProcessor).end()
.end();
上面代码中的处理器(myProcessor)如下:
counter.incrementAndGet(); //atomic counter
if(counter.get()==3)
{
exchange.setException(new RuntimeException());
throw new RuntimeCamelException();
}
但是,当我从路线中删除聚合时,Split可以在Exception上停止路线。
答案 0 :(得分:2)
在同一工作单元中使用复合消息处理器EIP,它是split + aggregate(fork / join)。
请参阅文档:http://camel.apache.org/composed-message-processor.html
请参阅仅限拆分器部分,您可以在其中为拆分器指定聚合策略以使其协同工作。