'Apache camel onCompletion call back doesn't trigger after route is completed

I have the following route setup in camel. I have posted the complete code here. After the ProcessorTwo is invoked, i am expecting the ProcessorOnComplete to be invoked, but it is not at all triggered. What i am missing here?

public class CamelRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("disruptor:routingChannel?concurrentConsumers=10")
            .onCompletion()
            .process(new ProcessorOnComplete())
            .end()
            .to("disruptor:processingOne?concurrentConsumers=10")
            .process(new ProcessorOne())
            .to("disruptor:processingTwo?concurrentConsumers=10")
            .process(new ProcessorTwo())
            .stop();
    }
}

public class ProcessorOne implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        System.out.println("Procesing one");
    }
}

public class ProcessorTwo implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        System.out.println("Procesing two");
    }
}

public class ProcessorOnComplete implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        System.out.println("Completion Mayuran");
    }
}

public class Main {
    public static void main(String[] args) throws Exception {
        CamelContext camelContext = new DefaultCamelContext();
        camelContext.addRoutes(new CamelRoute());
        camelContext.start();
        
        ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
        
        producerTemplate.sendBody("disruptor:routingChannel", "Message");
        
        Thread.sleep(1000*1000);
    }
}


Solution 1:[1]

onCompletion() runs when I test it, provided I have consumers for the messages sent to the disruptor queues.

You'll see the behaviour you describe if the Exchange is InOnly and you don't have anything consuming the messages sent to disruptor:processingOne or disruptor:processingTwo

The onCompletion is waiting for the messages in the disruptor queues to be processed.

The processors ProcessorOne() and ProcessorTwo() are called because camel doesn't wait for a response as the exchange is InOnly.

If the Exchange is InOut then the route would wait for a response from the first disruptor and probably timeout after 30 seconds. So you wouldn't see your messages from the processors.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pcoates