我有一条骆驼路线,看起来像下面的路线。如果所有记录解析成功,那么我会从onCompletion步骤收到一封电子邮件。如果一条记录得到一个异常,那么其余的记录将被处理,这很好,但onCompletion步骤不会触发。Apache Camel路由:发生异常时onCompletion没有达到?
我想让onCompletion步骤运行,即使出现错误并且能够发送消息说“路由已完成但有错误”。我怎样才能做到这一点?
<route id="route1">
<from uri="file://C:/TEMP/load?noop=true&idempotentRepository=#sysoutStore&sorter=#externalDataFilesSorter"/>
<choice>
<when>
<simple>${file:name} regex '*file.*.(txt)'</simple>
<to uri="direct:RouteFile" />
</when>
</choice>
</route>
<route id="testRouteDirect">
<from uri="direct:RouteFile" />
<onException>
<exception>java.lang.IllegalArgumentException</exception>
<redeliveryPolicy maximumRedeliveries="1" />
<handled>
<constant>true</constant>
</handled>
<to uri="log:java.lang.IllegalArgumentException"></to>
</onException>
<onException>
<exception>java.text.ParseException</exception>
<redeliveryPolicy maximumRedeliveries="1" />
<handled>
<constant>true</constant>
</handled>
<to uri="log:java.text.ParseException"></to>
</onException>
<split parallelProcessing="false" strategyRef="exchangePropertiesAggregatorStrategy" >
<tokenize token="\r\n"/>
<to uri="log:Record"></to>
</split>
<onCompletion>
<to uri="log:completion"></to>
<to uri="smtp://mail.com?contentType=text/html&[email protected]&[email protected]&subject=we're done" />
</onCompletion>
</route>
在doTry()和doCatch()中围绕处理部分。失败的记录将被捕获,然后您可以决定记录它们或者与他们一起做其他事情。路线将继续处理,因此它应该触发OnCompletion。 –
无论有什么例外情况,onCompletion都应该启动。也许在第一条路线的cbr块之前发生异常? –