Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BC238F79D for ; Wed, 20 Mar 2013 08:34:29 +0000 (UTC) Received: (qmail 32512 invoked by uid 500); 20 Mar 2013 08:34:29 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 32344 invoked by uid 500); 20 Mar 2013 08:34:28 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 32316 invoked by uid 99); 20 Mar 2013 08:34:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Mar 2013 08:34:28 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of ullgren@gmail.com designates 209.85.214.175 as permitted sender) Received: from [209.85.214.175] (HELO mail-ob0-f175.google.com) (209.85.214.175) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Mar 2013 08:34:24 +0000 Received: by mail-ob0-f175.google.com with SMTP id uz6so1318962obc.20 for ; Wed, 20 Mar 2013 01:34:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=4gEvLaAI6vICysriTsbCJT6z33ObNmmYCjGGBenj22U=; b=mSw5HARTpttioXWBolpzIILQVtfb6KS9ZIjTyOic8uqvJdD2zZ5cNxAbN+rkS9You6 kTQQ6f3Rss/enWnvg4vp3VvoVEO6vZlxOIMtntvXhH8qdzANwaV2NnO7zKJQNcEUOLTX eOl+pYyF+X7OS8XsL2lnlpkVqeVwrpbMGZ3QIuJvub6Lfb/iIx7pbAbCf/gwe3zoP8p0 Tz1EwJQab7W+Md2td1aYlZ2IgDDyFySmVxUoErUIpawvvJYbt0D7EPGYE3F1p9clBwQP PnliKw0kYZk1h4zbB4wTnbI980113f+fjR5Rv95Zj0sYy85L/tktb8pw2b+mj9ghnVDN Y0/A== MIME-Version: 1.0 X-Received: by 10.60.3.10 with SMTP id 10mr3603213oey.61.1363768443620; Wed, 20 Mar 2013 01:34:03 -0700 (PDT) Received: by 10.76.172.195 with HTTP; Wed, 20 Mar 2013 01:34:03 -0700 (PDT) In-Reply-To: References: Date: Wed, 20 Mar 2013 09:34:03 +0100 Message-ID: Subject: Re: How to schedule FTP with quartz? From: Pontus Ullgren To: users@camel.apache.org Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked by ClamAV on apache.org Hello, On Tue, Mar 19, 2013 at 11:22 PM, Chris Wolf wrote: > On Mon, Mar 18, 2013 at 4:57 PM, Pontus Ullgren wrote: >> Hello Chris, >> >> On Mon, Mar 18, 2013 at 8:54 PM, Chris Wolf wrote: >>> Claus, >>> >>> I have a few further questions about CronScheduledRoutePolicy. I >>> noticed that it has setters such as setRouteStartTime, >>> setRouteStopTime, each which takes a cron expression string. What I'm >>> looking for is to be able to use a cron expression for the start, but >>> a relative time length for stop. Otherwise, I need to write code to >>> parse the start time expression, then calculate a stop time cron >>> expression. Any ideas? >>> >> Depending on your needs you could enable "sendEmptyMessageWhenIdle" on >> the endpoint and then suspend the route when you receive a empty >> message. Which means that there is no more files to poll at the >> moment. >> You can use the content based route EIP for this. > > That is interesting to know, thanks. In my case, the files at the > remote end are themselves deposited at an irregular rate, but within a > defined time window, so during that time window, there will be > intermittent idleness... >> >> Another solution would be to write your own RoutePolicy to take care >> of your needs. > > Yes, this sounds like the best approach... > > >> >> I just started to wonder if it might be possible to combine the >> CronScheduledRoutePolicy with a SimpleScheduledRoutePolicy. >> I have _not_ tested this so I'm not sure if it works. It might be that >> there is a collision in the way they work with Quartz. >> >>> Also I see that CronScheduledRoutePolicy has setRouteResumeTime, >>> setRouteSuspendTime such that for my FTP poll window, I could either >>> do start/stop or resume/suspend - which is recommended? >>> >> I would highly recommend resume/suspend. >> I've had some thread leak problem with the file component when it was >> repetitively started/stopped. > > Ok, but I guess the first policy callback with be onStart since the > route will be > configured with noAutoStartup(), so upon that first onStart, I'll > suspend then toggle > between onSuspend/onResume... > Yes this is what I do. We have a route that should start 06:30 each day and then poll all files that are in the folder at that time. After that it should suspend. Here is some pseudo code. SuspendRouteProcessor is a processor that suspends the route based on route id. --- String cronStr = "* 30 6 * * * ?"; String input = "ftp://user@remotehost/inbox?sendEmptyMessageWhenIdle=true&password=secret"; CronScheduledRoutePolicy scheduledRP = new CronScheduledRoutePolicy(); scheduledRoutePolicy.setRouteStartTime(cronStr); scheduledRoutePolicy.setRouteResumeTime(cronStr); from(input) .routeId("input1") .routePolicy(versionPolicy, scheduledRoutePolicy) .noAutoStartup() .choice() .when(body().isNotNull()) .to("direct:processFiles") .end() .log(LoggingLevel.DEBUG, "All files processed, suspend route") .process(new SuspendRouteProcessor("input1")) ; -- The only downside with this is that after the initial start we get a WARN log message that the route can not be started since it is in suspend state. But as long as you can live with the WARN log it works. >> >> // Pontus >> >>> Thanks, >>> >>> Chris >>> >>> On Sat, Mar 2, 2013 at 1:43 AM, Claus Ibsen wrote: >>>> Hi >>>> >>>> See about route policy >>>> http://camel.apache.org/routepolicy >>>> >>>> And the scheduled route policy >>>> http://camel.apache.org/scheduledroutepolicy.html >>>> >>>> On Sat, Mar 2, 2013 at 12:15 AM, Chris Wolf wrote: >>>>> I have a requirement to download files via FTP during a certain time >>>>> window and according to a schedule. e.g. Only on trading days between >>>>> 6:30AM and 7:00AM. The FTP component, alone, seems to just do >>>>> indefinite polling according to delay/initialDelay. >>>>> >>>>> From the "Camel In Action" book, chapter 7, I see some examples of >>>>> sending a text message with the Timer and Quartz components, but I >>>>> can't quite see how to put that together to implement "kicking off >>>>> routes at specified intervals", mentioned in the best practices list >>>>> at the end of that chapter. How would I use quartz to stop/start the >>>>> FTP component, or the route that it's in? >>>>> >>>>> Thanks, >>>>> >>>>> Chris >>>> >>>> >>>> >>>> -- >>>> Claus Ibsen >>>> ----------------- >>>> Red Hat, Inc. >>>> FuseSource is now part of Red Hat >>>> Email: cibsen@redhat.com >>>> Web: http://fusesource.com >>>> Twitter: davsclaus >>>> Blog: http://davsclaus.com >>>> Author of Camel in Action: http://www.manning.com/ibsen