How to remove all routes in camel context

878 Views Asked by At

How to remove all route definitions in camel context ...something like below

context.removeRouteDefinitions(context.getRouteDefinitions());
2

There are 2 best solutions below

0
On

Please try to call this as bean method from your route:

  public void removeRoutes(Exchange exchange) {
            new Thread(() -> {
                try {
 exchange.getContext().stopRoute("currentRoute");
 exchange.getContext().removeRouteDefinitions(context.getRouteDefinitions());

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }).start();
   }
0
On
 context.removeRouteDefinitions(new ArrayList(context.getRouteDefinitions()));