How to stop camel dynamic route on exception

Viewed 1129

How do I stop a camel route when there is an exception. My dynamic route is consuming jms and sending to reactive endpoint.

camelContext.addRoutes(New GenerateRoute());

Route generator class is as below:

public class GenerateRoute extends RouteBuilder {

@Override
public void configure() {
    from("jms:queue:myQueue")
        .toF("reactive-streams:myStream").setId("myRoute");
}}
2 Answers

You can use handled and continued. in the onException clause. "Continued allows you to both handle and continue routing in the original route as if the exception did not occur." if continued is false the routing won't go back to the original route.

DSL:

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

Java:

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

Refer to: https://camel.apache.org/manual/latest/exception-clause.html#

Try this

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