You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by contactreji <co...@gmail.com> on 2016/03/18 09:33:46 UTC

Camel App as a batch

Hey guys

I am need to have an application which terminates once the exchanges are
completed. I used a main class like follows to boot my application which did
the job for me.

*
import org.apache.camel.spring.SpringCamelContext;
import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
import org.springframework.context.ApplicationContext;

public class AppBoot {
    public static void main(String[] args) throws Exception
    {
        ApplicationContext ac = new
ClassPathXmlApplicationContext("/META-INF/spring/camel-context.xml");
        SpringCamelContext camelContext = (SpringCamelContext)
ac.getBean("MyContest");
        camelContext.start();
        //Loading time for all camel routes
        Thread.sleep(10000);
        //Stop camel context only once Inflight exchanges are 0. i.e no
camel routes are processing any data
        while(camelContext.getInflightRepository().size()>0)
        {
            Thread.sleep(5000);
            System.out.println("Application Running with inflight exchanges
= "+camelContext.getInflightRepository().size());
        }
        System.out.println("Application ran for "+camelContext.getUptime());
        camelContext.stop();
    }
}*


I decided to monitor the number of inflight exchanges as a criteria for
terminating job.

But this way of doing things failed when exchanges were sent to camel
aggregators. My aggregator has a timeout value of 30 seconds and if new
exchanges don't arrive in aggregator, the condition
camelContext.getInflightRepository().size()>0 evaluates to false and routes
start graceful shutdown..


Is there a way I can keep a check on my aggregator bucket as well? Or
probably a better method of achieving this feature?

Cheers
-Reji



-----
Reji Mathews
Sr. Developer - Middleware Integration / SOA ( Open Source - Apache Camel & Jboss Fuse ESB | Mule ESB )
LinkedIn - http://in.linkedin.com/pub/reji-mathews/31/9a2/40a
Twitter - reji_mathews
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-App-as-a-batch-tp5779259.html
Sent from the Camel - Users mailing list archive at Nabble.com.