Hello,

I'm trying to stop a route from a processor. The route is Quartz-triggered
(via context.startRoute()). The route in question is defined like this:

        from("file:///tmp/x/?sendEmptyMessageWhenIdle=true")
                .noAutoStartup()
                .routeId(nameConsumer)
                .choice()
                    .when(body().isNull()).log("stopping route")
                        .process(
                            new Processor() {
                                @Override
                                public void process(final Exchange exchange)
throws Exception {                                   
                                   
getContext().getInflightRepository().remove(exchange);
                                    // try to stop the consumer, the polling
field of the ScheduledBatchPollingConsumer must be false? This doesn't work:
                                   
getContext().getRoute(exchange.getFromRouteId()).getConsumer().stop();
                                    // Remove the route entry from the
inflight repo -- this brings the pending size down by 1:
                                    getContext().getInflightRepository()
                                       
.removeRoute(exchange.getFromRouteId());
                                   
getContext().stopRoute(exchange.getFromRouteId());
                                }
                            }
                        )
                    .otherwise().to("seda:" + nameSeda +
"?waitForTaskToComplete=Never");


The idea was to use empty messages to signal when there are no more files to
process (sendEmptyMessageWhenIdle).

Problem is if I only remove(exchange) and
stopRoute(exchange.getFromRouteId()) Camel complains that there are 2
remaining pending exchanges:

[Camel (camel-1) thread #3 - ShutdownTask] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are still 2
inflight and pending exchanges to complete, timeout in 299 seconds.

Removing the route entry from the inflight repository brings this number
down by 1. But the other "pending exchange" seems to be there due to the
fact that getPendingExchangesSize in ScheduledBatchPollingConsumer returns 1
all the time if its state is "polling", a comment reads:

            // force at least one pending exchange if we are polling as
there is a little gap
            // in the processBatch method and until an exchange gets
enlisted as in-flight
            // which happens later, so we need to signal back to the
shutdown strategy that
            // there is a pending exchange. When we are no longer polling,
then we will return 0


I've tested with Camel 2.10/2.11. 

Any hints? Thanks in advance.
mdo






--
View this message in context: 
http://camel.465427.n5.nabble.com/stopRoute-Waiting-as-there-are-still-X-inflight-and-pending-exchanges-to-complete-tp5729348.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to