如何在异常情况下停止骆驼动态路线

时间:2020-07-01 04:18:40

标签: apache-camel spring-camel

出现异常时,如何停止骆驼路线。我的动态路由消耗了jms并发送到反应性端点。

12aAB

路由生成器类如下:

camelContext.addRoutes(New GenerateRoute());

2 个答案:

答案 0 :(得分:2)

尝试一下

    from("jms:queue:myQueue")
            .routeId("myRoute")
            .doTry()
                .toF("reactive-streams:myStream")
            .doCatch(Exception.class)
                .process(exchange -> exchange.getFromEndpoint().stop())
            .end();

答案 1 :(得分:1)

您可以使用handledcontinued。在onException子句中。 “继续使您可以处理并继续在原始路由中进行处理,就好像未发生异常一样。”如果continued为假,则路由不会返回到原始路由。

DSL:

<onException>
    <exception>java.lang.IllegalArgumentException</exception>
    <continued><constant>false</constant></continued>
</onException>

Java:

onException(IllegalArgumentException.class).continued(fasle);

引用:https://camel.apache.org/manual/latest/exception-clause.html#