camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cwhistler <chadd.whist...@sungard.com>
Subject Re: Route does not shut down if there is no message on poll.
Date Mon, 01 Aug 2011 11:33:51 GMT
I think I have this worked out now.  I found the PollingConsumerPollStrategy
interface so I created an EmptyPollStrategy class.  I changed the begin()
method to simply return true.  In the commit() method I checked the
numberPolled parameter and if it is 0 then I just stop the consumer.  I left
the rollback() method unchanged.

public boolean begin(Consumer consumer, Endpoint endpoint)
{
    return true;
}

public void commit(Consumer consumer, Endpoint endpoint, int numberPolled)
{
    if (numberPolled == 0)
    {
	try
	{
		consumer.stop();
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
    }
}

public boolean rollback(Consumer arg0, Endpoint arg1, int arg2, Exception
arg3) throws Exception
{
    // TODO Auto-generated method stub
    return false;
}


OK so to run my route only at 9:35 every day I have setup the route as
follows.  The references to the filters and processors are all wired up with
Spring.

I created the StopRouteProcessor to stop the route when it has read all of
the files that were initially polled.

The .noAutoStartup() seemed to be required as the route always started with
camel and then at the scheduled time.

CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
policy.setRouteStartTime("0 35 9 * * ?");
		
from("file://test/input?preMove=inprogress&pollStrategy=#emptyPollStrategy&delete=true&filter=#errorFileFilter")
    .routePolicy(policy)
    .noAutoStartup()
    .routeId("timedroute")
    .processRef("addHeadersProcessor")
    .to("file://test/output")
    .onCompletion().process(new StopRouteProcessor("timedroute").end()
;

The only problem I'm seeing now is when I have to schedule this route to run
more than once.  So for example I want 9:35 and then again at 11:35.  By
letting Spring wire up the EmptyPollStrategy, it is only effective with the
first scheduled execution.  It never runs on the 2nd schedule.

--
View this message in context: http://camel.465427.n5.nabble.com/Route-does-not-shut-down-if-there-is-no-message-on-poll-tp476108p4654806.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message