onCompletion is per message. If you route from a JMS queue then its also per message, and there is no easy way of knowing that the queue is empty.
You would need to think about alternative way of figuring out if the queue is empty. Depending on the message broker you use, they may have some API to support that. For example Apache ActiveMQ has advisory messages you can use to send a message to a queue, and get back a reply message with the current stats of the queue. You can also have some way like if there has not been any new message picked up from the Camel route in X time, then we assume the queue is empty. You can also use the aggregator EIP and aggregate all the messages from the queue. And then use a timeout completion on the aggregator, then that timeout is hit when the is empty, as there was no new messages in X time. On Thu, Nov 7, 2013 at 11:03 AM, jay <mylifemyrulesmyw...@gmail.com> wrote: > Hi Guys, > > I have a requirement to call some bean/pojo or processor to clean some stuff > once all the messages are processed from the queue (_from). > > But my on completion is getting invoked for every single message. Could > someone let me know your views on what is wrong i am doing here. > > below is my code : > onCompletion().beanRef("MyBean", "xyzMethod"); > from(_from).routeId("myRouteID") > .process(new MyProcessor()) > .choice() > .when(header("VALID_MSG").isEqualTo("false" )) > .log(" Error") > .otherwise() > .aggregate( header("ID"), new > MyAggregator()).completionTimeout(getAggregationTimeout()) > .process(processor); > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/OnCompletion-issue-in-Camel-ActiveMQ-tp5742771.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen ----------------- Red Hat, Inc. Email: cib...@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen