简体   繁体   English

Apache Camel路由:发生异常时未达到onCompletion吗?

[英]Apache Camel route: onCompletion not reached when exception occurs?

I have a Camel route that looks something like the one below. 我有一条骆驼路线,看起来像下面的路线。 If all records parse successfully, then I get an email from the onCompletion step. 如果所有记录都成功解析,那么我将从onCompletion步骤中收到一封电子邮件。 If one record gets an exception then the rest of the records will process, which is fine, but the onCompletion step does not fire. 如果一条记录发生异常,则将处理其余记录,这很好,但是不会触发onCompletion步骤。

What I'd like is for the onCompletion step to run even if there are errors and to be able to send a message saying "route completed with errors". 我想要的是即使有错误也可以运行onCompletion步骤,并能够发送一条消息,指出“路线已完成,但有错误”。 How can I do this? 我怎样才能做到这一点?

        <route id="route1">
            <from uri="file://C:/TEMP/load?noop=true&amp;idempotentRepository=#sysoutStore&amp;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&amp;to=done@test.com&amp;from=route@test.com&amp;subject=we're done" />
              </onCompletion>
        </route>

The best part of your route is, you have onException inside your route with handled=true. 路由的最佳部分是,您的路由中包含onException,其值为handler = true。 So move your onCompletion to the parent route(route1), It should work ! 因此,将您的onCompletion移到父route(route1),应该可以!

There are a bunch of tickets related to oncompletion on the camel site: Camel Jira URL . 骆驼网站上有大量与oncompletion相关的门票: Camel Jira URL I upgraded to a newer version of camel & I don't get this issue any more. 我已升级到较新版本的骆驼,并且不再遇到此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM