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 D23E6D60A for ; Sun, 26 Aug 2012 07:14:55 +0000 (UTC) Received: (qmail 85983 invoked by uid 500); 26 Aug 2012 07:14:54 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 85667 invoked by uid 500); 26 Aug 2012 07:14:54 -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 85652 invoked by uid 99); 26 Aug 2012 07:14:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Aug 2012 07:14:54 +0000 X-ASF-Spam-Status: No, hits=0.6 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of claus.ibsen@gmail.com designates 209.85.217.173 as permitted sender) Received: from [209.85.217.173] (HELO mail-lb0-f173.google.com) (209.85.217.173) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Aug 2012 07:14:49 +0000 Received: by lbbgm13 with SMTP id gm13so2242611lbb.32 for ; Sun, 26 Aug 2012 00:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=T6R7D+s9kd79oO/sMZHy0RK9gvPkp6/D02YTx20QOc8=; b=jUH1n60H/kr1AJSa7Tvybk0HLYAcWY1nKiJVe/zueO958vxGIe2fjRUQN5SKlfzjTo kSXa12FSovMj4qpkgoLUvka5ViM2gpgZL0i96FODUPiIOpQ0DpUwIoIg6H1VXnRKauWs f7NNhxtuSScvjpKBnTJrVLZrM+sIt9h3MoRen008NdRDvekkjnpSsUhqSgt4WxmaKLqM Z9PayJY2IdMMAgkmp0KFAwj8eTbwyWQ1wDF0RagoRYz0aRYLbrTKD+iqQ0oDHb4GyEs/ Dhw3zpcGbdT2xX0T6IDzJccsSbjhDuiPlocq1SmxzlROz9ZnUNhjS00K1UPE+B1ur7qc l4eA== Received: by 10.112.28.226 with SMTP id e2mr4782056lbh.96.1345965268427; Sun, 26 Aug 2012 00:14:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.7.230 with HTTP; Sun, 26 Aug 2012 00:14:08 -0700 (PDT) In-Reply-To: <1345914804494-5718059.post@n5.nabble.com> References: <1345914804494-5718059.post@n5.nabble.com> From: Claus Ibsen Date: Sun, 26 Aug 2012 09:14:08 +0200 Message-ID: Subject: Re: Periodic route activation use case To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org On Sat, Aug 25, 2012 at 7:13 PM, Ashwin Pejavar wrote: > I have a use-case where I need to consume files at a fixed cron schedule. > > For example, I need my input route to resume everyday at 6AM, process all > files collected in the input directory and go into suspension till 6AM the > following day. > > I was hoping the CronScheduledRoutePolicy would be useful, but that doesn't > quite do what I need. I can use it to start the route at 6AM, but there > seems to be no way of automatically suspending it when all the files are > processed. > > Is there a way of doing this in Camel? > See this FAQ http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html You could possible either extend the cron scheduled route policy, and add logic in the onExchangeDone and figure out if its the last exchange from the file batch. And then if so stop/suspend the consumer. The file consumer is cheap to suspend as its an internal flag that indicate its suspended (AFAIR). And therefore you most likely wont need to use a separate thread as the FAQ tells to do. The file consumer will set a property on the exchange when there is no more files (eg the batch is complete) exchange.setProperty(Exchange.BATCH_COMPLETE, true); So you can check for that property, and know when you are done, and can suspend the consumer. Something a like onExchangeDone(Route route, Exchange exchange) { // check for batch complete if (...) { // stop will favor suspend over stopping, so its fine to invoke this method stopConsumer(route.getConsumer()); } } And on the file component you would need to enable the sendEmptyMessageWhenIdle=true option to send an empty message if there is no files. So the routing will kick in. You would need to cater for an empty message in your route logic though. A total different approach would be to use a custom PollingConsumerPollStrategy on the file endpoint. http://camel.apache.org/polling-consumer.html It has callbacks when the polling starts / commits. And the number of polled messages (eg number of files found). You can then use that to implement logic to suspend the consumer in the commit method. That may be an easier task to try out at first. Extending the DefaultPollingConsumerPollStrategy and override the commit method. > > > -- > View this message in context: http://camel.465427.n5.nabble.com/Periodic-route-activation-use-case-tp5718059.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.com Author of Camel in Action: http://www.manning.com/ibsen