3
votes

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?

1
@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 processingmaxdev
Use camel.apache.org/graceful-shutdown.html but set the timeout to 0 or just 1-2 seconds.Souciance Eqdam Rashti
@SoucianceEqdamRashti The problem is not about configuring the shutdown strategy.maxdev
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

1 Answers

1
votes

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