Grokbase Groups Camel users June 2010
FAQ
Hi

I have a setup where I start a route with with a quartz timer. This route
then starts another route that does the actual work of fetching files from
an ftp and then shuts down.

The problem with this workaround is that the ftp-fetching route will never
shut down if there are no messages on the ftp since it is a message reaching
the end of the route that activates the shut down.

Any ideas how to fix this? :)

<!-- Scheduled start-FTP trigger route -->
<route id="StartFtpTriggerRoute" autoStartup="true">
<from uri="quartz://scheduledpoll?cron={{cron.poll}}" />
<setHeader headerName="routeToStart">
<constant>FtpPollingRoute</constant>
</setHeader>
<bean ref="RouteController" method="start" />
<stop />
</route>

<!-- Route-stopping route -->
<route>
<from uri="seda:StopRouteRoute" />
<bean ref="RouteController" method="stop" />
</route>

<!-- FTP polling route -->
<route id="FtpPollingRoute" errorHandlerRef="deadLetterErrorHandler"
autoStartup="false">
<from
uri="ftp:{{ftp.server}}{{ftp.inbox}}?username={{ftp.user}}&amp;password={{ftp.password}}&amp;delete=true&amp;disconnect=true"
/>
<onCompletion>
<filter>
<simple>${property.CamelBatchComplete} == true</simple>
<setHeader headerName="routeToStop">
<constant>FtpPollingRoute</constant>
</setHeader>
<to uri="seda:StopRouteRoute" />
</filter>
</onCompletion>
<to uri="file:data" />
</route>


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

Search Discussions

  • Willem Jiang at Jun 8, 2010 at 1:42 pm
    Yes, if there is no file that ftp endpoint poll, the onCompletion will
    never be called, so this route will not be shutdown.

    Maybe we can consider to add a option on generic file endpoint to break
    the polling loop if there is no file can be polled.

    Willem


    ankelee wrote:
    Hi

    I have a setup where I start a route with with a quartz timer. This route
    then starts another route that does the actual work of fetching files from
    an ftp and then shuts down.

    The problem with this workaround is that the ftp-fetching route will never
    shut down if there are no messages on the ftp since it is a message reaching
    the end of the route that activates the shut down.

    Any ideas how to fix this? :)

    <!-- Scheduled start-FTP trigger route -->
    <route id="StartFtpTriggerRoute" autoStartup="true">
    <from uri="quartz://scheduledpoll?cron={{cron.poll}}" />
    <setHeader headerName="routeToStart">
    <constant>FtpPollingRoute</constant>
    </setHeader>
    <bean ref="RouteController" method="start" />
    <stop />
    </route>

    <!-- Route-stopping route -->
    <route>
    <from uri="seda:StopRouteRoute" />
    <bean ref="RouteController" method="stop" />
    </route>

    <!-- FTP polling route -->
    <route id="FtpPollingRoute" errorHandlerRef="deadLetterErrorHandler"
    autoStartup="false">
    <from
    uri="ftp:{{ftp.server}}{{ftp.inbox}}?username={{ftp.user}}&amp;password={{ftp.password}}&amp;delete=true&amp;disconnect=true"
    />
    <onCompletion>
    <filter>
    <simple>${property.CamelBatchComplete} == true</simple>
    <setHeader headerName="routeToStop">
    <constant>FtpPollingRoute</constant>
    </setHeader>
    <to uri="seda:StopRouteRoute" />
    </filter>
    </onCompletion>
    <to uri="file:data" />
    </route>
  • Claus Ibsen at Jun 8, 2010 at 1:44 pm
    Hi

    You handle the lifecycles of your own routes then.
    So I bet in RouteController you can shutdown the routes manually.

    But I also think we should offer an option on Camel to let it shutdown
    any routes which has been manually started/added later.
    I will create a JIRA for that.

    On Tue, Jun 8, 2010 at 10:53 AM, ankelee wrote:

    Hi

    I have a setup where I start a route with with a quartz timer. This route
    then starts another route that does the actual work of fetching files from
    an ftp and then shuts down.

    The problem with this workaround is that the ftp-fetching route will never
    shut down if there are no messages on the ftp since it is a message reaching
    the end of the route that activates the shut down.

    Any ideas how to fix this? :)

    <!-- Scheduled start-FTP trigger route -->
    <route id="StartFtpTriggerRoute" autoStartup="true">
    <from uri="quartz://scheduledpoll?cron={{cron.poll}}" />
    <setHeader headerName="routeToStart">
    <constant>FtpPollingRoute</constant>
    </setHeader>
    <bean ref="RouteController" method="start" />
    <stop />
    </route>

    <!-- Route-stopping route -->
    <route>
    <from uri="seda:StopRouteRoute" />
    <bean ref="RouteController" method="stop" />
    </route>

    <!-- FTP polling route -->
    <route id="FtpPollingRoute" errorHandlerRef="deadLetterErrorHandler"
    autoStartup="false">
    <from
    uri="ftp:{{ftp.server}}{{ftp.inbox}}?username={{ftp.user}}&amp;password={{ftp.password}}&amp;delete=true&amp;disconnect=true"
    />
    <onCompletion>
    <filter>
    <simple>${property.CamelBatchComplete} == true</simple>
    <setHeader headerName="routeToStop">
    <constant>FtpPollingRoute</constant>
    </setHeader>
    <to uri="seda:StopRouteRoute" />
    </filter>
    </onCompletion>
    <to uri="file:data" />
    </route>


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


    --
    Claus Ibsen
    Apache Camel Committer

    Author of Camel in Action: http://www.manning.com/ibsen/
    Open Source Integration: http://fusesource.com
    Blog: http://davsclaus.blogspot.com/
    Twitter: http://twitter.com/davsclaus
  • Claus Ibsen at Jun 8, 2010 at 1:46 pm
    Hi

    Ticket is
    https://issues.apache.org/activemq/browse/CAMEL-2800
    On Tue, Jun 8, 2010 at 3:44 PM, Claus Ibsen wrote:
    Hi

    You handle the lifecycles of your own routes then.
    So I bet in RouteController you can shutdown the routes manually.

    But I also think we should offer an option on Camel to let it shutdown
    any routes which has been manually started/added later.
    I will create a JIRA for that.

    On Tue, Jun 8, 2010 at 10:53 AM, ankelee wrote:

    Hi

    I have a setup where I start a route with with a quartz timer. This route
    then starts another route that does the actual work of fetching files from
    an ftp and then shuts down.

    The problem with this workaround is that the ftp-fetching route will never
    shut down if there are no messages on the ftp since it is a message reaching
    the end of the route that activates the shut down.

    Any ideas how to fix this? :)

    <!-- Scheduled start-FTP trigger route -->
    <route id="StartFtpTriggerRoute" autoStartup="true">
    <from uri="quartz://scheduledpoll?cron={{cron.poll}}" />
    <setHeader headerName="routeToStart">
    <constant>FtpPollingRoute</constant>
    </setHeader>
    <bean ref="RouteController" method="start" />
    <stop />
    </route>

    <!-- Route-stopping route -->
    <route>
    <from uri="seda:StopRouteRoute" />
    <bean ref="RouteController" method="stop" />
    </route>

    <!-- FTP polling route -->
    <route id="FtpPollingRoute" errorHandlerRef="deadLetterErrorHandler"
    autoStartup="false">
    <from
    uri="ftp:{{ftp.server}}{{ftp.inbox}}?username={{ftp.user}}&amp;password={{ftp.password}}&amp;delete=true&amp;disconnect=true"
    />
    <onCompletion>
    <filter>
    <simple>${property.CamelBatchComplete} == true</simple>
    <setHeader headerName="routeToStop">
    <constant>FtpPollingRoute</constant>
    </setHeader>
    <to uri="seda:StopRouteRoute" />
    </filter>
    </onCompletion>
    <to uri="file:data" />
    </route>


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


    --
    Claus Ibsen
    Apache Camel Committer

    Author of Camel in Action: http://www.manning.com/ibsen/
    Open Source Integration: http://fusesource.com
    Blog: http://davsclaus.blogspot.com/
    Twitter: http://twitter.com/davsclaus


    --
    Claus Ibsen
    Apache Camel Committer

    Author of Camel in Action: http://www.manning.com/ibsen/
    Open Source Integration: http://fusesource.com
    Blog: http://davsclaus.blogspot.com/
    Twitter: http://twitter.com/davsclaus
  • Ankelee at Jun 14, 2010 at 3:58 pm
    Hi Claus

    I'm not really sure how/if this ticket relates to the issue I have.
    Can you elaborate?

    I'd see more use in Willems suggestion.

    Either feature could be used for my use case:
    * Stop route if poll had no messages.

    or

    *Have cron-statements directly on the file/ftp/whatever endpoints.

    I don't know which is easiest in scope - but maybe there should be created a
    ticket for both?




    Claus Ibsen-2 wrote:
    Hi

    Ticket is
    https://issues.apache.org/activemq/browse/CAMEL-2800
    On Tue, Jun 8, 2010 at 3:44 PM, Claus Ibsen wrote:
    Hi

    You handle the lifecycles of your own routes then.
    So I bet in RouteController you can shutdown the routes manually.

    But I also think we should offer an option on Camel to let it shutdown
    any routes which has been manually started/added later.
    I will create a JIRA for that.

    On Tue, Jun 8, 2010 at 10:53 AM, ankelee wrote:

    Hi

    I have a setup where I start a route with with a quartz timer. This
    route
    then starts another route that does the actual work of fetching files
    from
    an ftp and then shuts down.

    The problem with this workaround is that the ftp-fetching route will
    never
    shut down if there are no messages on the ftp since it is a message
    reaching
    the end of the route that activates the shut down.

    Any ideas how to fix this? :)

    <!-- Scheduled start-FTP trigger route -->
    <route id="StartFtpTriggerRoute" autoStartup="true">
    <from uri="quartz://scheduledpoll?cron={{cron.poll}}" />
    <setHeader headerName="routeToStart">
    <constant>FtpPollingRoute</constant>
    </setHeader>
    <bean ref="RouteController" method="start" />
    <stop />
    </route>

    <!-- Route-stopping route -->
    <route>
    <from uri="seda:StopRouteRoute" />
    <bean ref="RouteController" method="stop" />
    </route>

    <!-- FTP polling route -->
    <route id="FtpPollingRoute" errorHandlerRef="deadLetterErrorHandler"
    autoStartup="false">
    <from
    uri="ftp:{{ftp.server}}{{ftp.inbox}}?username={{ftp.user}}&amp;password={{ftp.password}}&amp;delete=true&amp;disconnect=true"
    />
    <onCompletion>
    <filter>
    <simple>${property.CamelBatchComplete} ==
    true</simple>
    <setHeader headerName="routeToStop">
    <constant>FtpPollingRoute</constant>
    </setHeader>
    <to uri="seda:StopRouteRoute" />
    </filter>
    </onCompletion>
    <to uri="file:data" />
    </route>


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


    --
    Claus Ibsen
    Apache Camel Committer

    Author of Camel in Action: http://www.manning.com/ibsen/
    Open Source Integration: http://fusesource.com
    Blog: http://davsclaus.blogspot.com/
    Twitter: http://twitter.com/davsclaus


    --
    Claus Ibsen
    Apache Camel Committer

    Author of Camel in Action: http://www.manning.com/ibsen/
    Open Source Integration: http://fusesource.com
    Blog: http://davsclaus.blogspot.com/
    Twitter: http://twitter.com/davsclaus
    --
    View this message in context: http://old.nabble.com/Route-does-not-shut-down-if-there-is-no-message-on-poll.-tp28815309p28881412.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Cwhistler at Jul 29, 2011 at 5:31 pm
    I realize this is an old post but it relates my exact issue.

    i have used quartz to schedule a route at a specific time of day. the route
    should poll a file folder and process any files in it and then shut down.
    The problem is if there are no files in that folder then the route never
    shuts down.

    I didn't see any details on the jira to see what was put in to fix this.

    so is there a way to do this?

    --
    View this message in context: http://camel.465427.n5.nabble.com/Route-does-not-shut-down-if-there-is-no-message-on-poll-tp476108p4647763.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Claus Ibsen at Jul 31, 2011 at 11:03 am

    On Fri, Jul 29, 2011 at 7:30 PM, cwhistler wrote:
    I realize this is an old post but it relates my exact issue.

    i have used quartz to schedule a route at a specific time of day.  the route
    should poll a file folder and process any files in it and then shut down.
    The problem is if there are no files in that folder then the route never
    shuts down.

    I didn't see any details on the jira to see what was put in to fix this.

    so is there a way to do this?
    How have you defined your routes 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-tp476108p4647763.html
    Sent from the Camel - Users mailing list archive at Nabble.com.


    --
    Claus Ibsen
    -----------------
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    Twitter: davsclaus, fusenews
    Blog: http://davsclaus.blogspot.com/
    Author of Camel in Action: http://www.manning.com/ibsen/
  • Cwhistler at Aug 1, 2011 at 11:34 am
    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 Jiang at Aug 2, 2011 at 1:03 am
    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
  • Cwhistler at Aug 2, 2011 at 5:22 pm
    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.
  • Cwhistler at Aug 5, 2011 at 1:31 pm
    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.
  • Willem Jiang at Aug 5, 2011 at 3:33 pm
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedJun 8, '10 at 8:54a
activeAug 5, '11 at 3:33p
posts12
users4
websitecamel.apache.org

People

Translate

site design / logo © 2022 Grokbase