Search code examples
javaspring-bootapache-camelmigration

How to get to RouteDefinition in Camel 3.x (migration from 2.x to 3.x)


I upgraded camel-parent from 2.x to 3.x. I had this use in code:

 exchange.getContext()
                .getRoute(exchange.getFromRouteId())
                .getRouteContext()
                .getRoute()
                .stop();
    

Now

 exchange.getContext()
                .getRoute(exchange.getFromRouteId())
                .getRouteContext()

gives us an interface where we cannot get to org.apache.camel.model.RouteDefinition instead we get org.apache.camel.NamedNode on which I cannot execute stop method. Could you tell me how can I get to this RouteDefinition so that I can execute stop method on it?


Solution

  • The new way to do it (in Camel 3) is to use the RouteController, eg:

    camelContext.getRouteController().suspendRoute("my-route-id");