4

We have a data processing application that runs on Karaf 2.4.3 with Camel 2.15.3.

In this application, we have a bunch of routes that import data. We have a management view that lists these routes and where each route can be started. Those routes do not directly import data, but call other routes (some of them in other bundles, called via direct-vm), sometimes directly and sometimes in a splitter.

Is there a way to also completely stop a route/therefore stopping the entire exchange from being further processed?

When simply using the stopRoute function like this:

route.getRouteContext().getCamelContext().stopRoute(route.getId());

I eventually get a success message with Graceful shutdown of 1 routes completed in 10 seconds - the exchange is still being processed though...

So I tried to mimic the behaviour of the StopProcessor by setting the stop property, but that also didn't help:

public void stopRoute(Route route) {
    try {
        Collection<InflightExchange> browse = route.getRouteContext().getCamelContext().getInflightRepository()
                .browse();
        for (InflightExchange inflightExchange : browse) {
            String exchangeRouteId = inflightExchange.getRouteId();
            if ((exchangeRouteId != null) && exchangeRouteId.equals(route.getId())) {
                this.stopExchange(inflightExchange.getExchange());
            }
        }
    } catch (Exception e) {
        Notification.show("Error while trying to stop route", Type.ERROR_MESSAGE);
        LOGGER.error(e, e);
    }
}

public void stopExchange(Exchange exchange) throws Exception {
    AsyncProcessorHelper.process(new AsyncProcessor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            AsyncProcessorHelper.process(this, exchange);
        }

        @Override
        public boolean process(Exchange exchange, AsyncCallback callback) {
            exchange.setProperty(Exchange.ROUTE_STOP, Boolean.TRUE);
            callback.done(true);
            return true;
        }
    }, exchange);
}

Is there any way to completely stop an exchange from being processed from outside the route?

maxdev
  • 2,491
  • 1
  • 25
  • 50
  • 1
    have you seen this page https://camel.apache.org/how-can-i-stop-a-route-from-a-route.html ? – ltsallas Jan 16 '17 at 09:01
  • @Itsallas I've seen it, but it says you should use the `stopRoute` function which for some reason doesn't stop the exchange from further processing – maxdev Jan 16 '17 at 09:16
  • Use http://camel.apache.org/graceful-shutdown.html but set the timeout to 0 or just 1-2 seconds. – Souciance Eqdam Rashti Jan 16 '17 at 09:28
  • @SoucianceEqdamRashti The problem is not about configuring the shutdown strategy. – maxdev Jan 16 '17 at 09:49
  • Isn't the problem that you don't want further exchanges to be processed and want an immediate stop to the route? – Souciance Eqdam Rashti Jan 16 '17 at 09:57
  • @SoucianceEqdamRashti I do. And it works for example when re-deploying a bundle. But I want to simply stop a route from code, but using `stopRoute` does not work. See my question – maxdev Jan 16 '17 at 10:07
  • I have used StopRoute before and it works to stop the route. It depends if you want it to stop gracefully or not. It has a 300 sec default timeout to let inflight exchanges to finish. If you don't want that to happen and want an immediate stop thereby disregarding inflight exchanges, try setting the timeout property to 0 or 1-2 sec. I have tested this and it worked on camel 2.17.0 – Souciance Eqdam Rashti Jan 16 '17 at 10:09
  • @SoucianceEqdamRashti Might work if you have a simple route that doesn't call other routes/uses a splitter.. I added this to the question. Like this it's not that easy to kill the entire exchange anymore.. – maxdev Jan 16 '17 at 10:18
  • I had a somewhat complicated route and my solution look a bit like this one: http://stackoverflow.com/questions/32379367/camel-how-to-stop-route-execution-on-exception – Souciance Eqdam Rashti Jan 16 '17 at 12:27
  • @SoucianceEqdamRashti That's right that would work, but alas it stops the entire context :( But I thought of a different solution - make a "gracefulCancelProcessor" inside the re-occuring routes, that cancels if a specific condition is met. This condition is then set from where I want to cancel processing. – maxdev Jan 16 '17 at 13:15
  • You can put the question on the Camel nabble forum site to see if others have done this. – Souciance Eqdam Rashti Jan 16 '17 at 13:34

1 Answers1

1

Can you get an exchange? I use exchange.setProperty(Exchange.ROUTE_STOP, true); Route stop flow and doesn't go to next route.

Andrew Lohr
  • 5,380
  • 1
  • 26
  • 38
evgenyi
  • 19
  • 2
  • Hey friend, thanks for the reply. Like I wrote in my question I already tried with `ROUTE_STOP` property, but that did not work. I did not try it in the new Karaf/Camel yet, maybe this works there now. – maxdev Sep 14 '17 at 11:13