Search code examples
javaapache-camelshutdown

How to speed up seda shutdown?


Is there any way to stop SedaConsumer without waiting for BlockingQueue.take(pollTimeout, ...) to return? I have a lot of sedas in my application and a graceful shutdown takes a lot of time. When DefaultShutdownStrategy shutdown sedaConsumers there are no more messages in the queue and no more messages will be produced (because of implementation of routes shutdown before). So each sedaConsumer has to wait about 1 second.

Is it possible to force doStop instead of prepareShutdown for seda? Or interrupt workers threads?

I know I can decrease pollTimeout, but I afraid it will affect runtime performance.


Solution

  • In SedaConsumer.java:

            try {
                // use the end user configured poll timeout
                exchange = queue.poll(pollTimeout, TimeUnit.MILLISECONDS);
                // Omitted
            } catch (InterruptedException e) {
                LOG.debug("Sleep interrupted, are we stopping? {}", isStopping() || isStopped());
                continue;
            } catch (Throwable e) {
                if (exchange != null) {
                    getExceptionHandler().handleException("Error processing exchange", exchange, e);
                } else {
                    getExceptionHandler().handleException(e);
                }
            }
    

    This construct is at most places in the thread where an InterruptedException can be thrown so if the consumer is stopping and is interrupted it will stop gracefully.