You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by cwhistler <ch...@sungard.com> on 2011/08/01 13:33:51 UTC

Re: Route does not shut down if there is no message on poll.

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.

Re: Route does not shut down if there is no message on poll.

Posted by Willem Jiang <wi...@gmail.com>.
Oh, the code is a part of CronScheduledRoutePolicy.

I show you the code is just for reminding you to check the route states.


On 8/3/11 1:21 AM, cwhistler wrote:
> sorr but I don't understand where I would put that code.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Route-does-not-shut-down-if-there-is-no-message-on-poll-tp476108p4659580.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Re: Route does not shut down if there is no message on poll.

Posted by cwhistler <ch...@sungard.com>.
just wanted to see if anyone had any other suggestions or help getting this
to work?

I just noticed that Camel originally had something on the file endpoint to
handle this.

consumer.generateEmptyExchangeWhenIdle  false  @deprecated. Option only for
the FileConsumer. If this option is true and there was no files to process
we simulate processing a single empty file, so an exchange is fired. Note:
In this situation the File attribute in FileExchange is null.  

Not sure why this was removed but it sure would resolve this issue.  Was
there some other replacement for this??

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

Re: Route does not shut down if there is no message on poll.

Posted by cwhistler <ch...@sungard.com>.
sorr but I don't understand where I would put that code.

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

Re: Route does not shut down if there is no message on poll.

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

Can you check the timedroute route states ?
CronScheduledRoutePolicy  start or resume the route when the route 
status is ready.

     ServiceStatus routeStatus = 
route.getRouteContext().getCamelContext().getRouteStatus(route.getId());
         if (action == Action.START) {
             if (routeStatus == ServiceStatus.Stopped) {
                 startRoute(route);
             } else if (routeStatus == ServiceStatus.Suspended) {
                 startConsumer(route.getConsumer());
             }
         }

Willem

On 8/1/11 7:33 PM, cwhistler wrote:
> 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.
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang