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 BCD41DEE9 for ; Fri, 10 Aug 2012 18:25:22 +0000 (UTC) Received: (qmail 376 invoked by uid 500); 10 Aug 2012 18:25:21 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 344 invoked by uid 500); 10 Aug 2012 18:25:21 -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 285 invoked by uid 99); 10 Aug 2012 18:25:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Aug 2012 18:25:21 +0000 X-ASF-Spam-Status: No, hits=4.5 required=5.0 tests=HTML_MESSAGE,SPF_SOFTFAIL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: softfail (nike.apache.org: transitioning domain of vishal.changrani@ericsson.com does not designate 216.139.236.26 as permitted sender) Received: from [216.139.236.26] (HELO sam.nabble.com) (216.139.236.26) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Aug 2012 18:25:14 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1SzttF-0001Lv-7P for users@camel.apache.org; Fri, 10 Aug 2012 11:24:53 -0700 Date: Fri, 10 Aug 2012 11:24:53 -0700 (PDT) From: vishal1981 To: users@camel.apache.org Message-ID: <0A099D1987C50144843A2A230447574510B6AA9A08@EUSAACMS0718.eamcs.ericsson.se> In-Reply-To: References: <1344364322551-5716940.post@n5.nabble.com> <0A099D1987C50144843A2A230447574510B6AA99E5@EUSAACMS0718.eamcs.ericsson.se> Subject: RE: Consuming a remote FTP server triggered by a route in Camel 2.9 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_15660_5114297.1344623093215" ------=_Part_15660_5114297.1344623093215 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Thanks for that solution. It works but I see that my FTP thread lingers around after it has done its job. Is this by design since I have created an FTP endpoint? Also is that thread connecting to the FTP URI continously or just sleeping? thanks again, V ________________________________ From: pontus.ullgren [via Camel] [mailto:ml-node+s465427n5717137h73@n5.nabble.com] Sent: Friday, August 10, 2012 2:11 PM To: Vishal Changrani Subject: Re: Consuming a remote FTP server triggered by a route in Camel 2.9 Hello, If you always get only one file (and the file name is the same each time) I think the poll enricher will do the same work for you. from("direct:start") .pollEnrich(ftpUri, 60000) .to("direct:result"); // Pontus On Fri, Aug 10, 2012 at 7:37 PM, vishal1981 <[hidden email]> wrote: > Thanks for the reply. > > I eneded up doing somethign like this based ... > Does that sound ok? > > > > public class OnDemandFtpConsumer implements Processor { > > private final CamelContext camelContext; > > private final String ftpUri; > > private static final Log logger = LogFactory.getLog(OnDemandFtpConsumer.class); > > public OnDemandFtpConsumer(CamelContext camelContext, String uri) > > { > > this.camelContext = camelContext; > > this.ftpUri = uri; > > } > > @Override > > public void process(final Exchange exchange) throws Exception { > > EventDrivenPollingConsumer consumer = null; > > Endpoint ftp = null; > > try > > { > > // create a ftp endpoint > > ftp = camelContext.getEndpoint(ftpUri); > > consumer = new EventDrivenPollingConsumer(ftp); > > consumer.start(); > > logger.trace(" Fetching exported file from URI "+ftpUri); > > // receive the remote ftp > > Exchange result = consumer.receive(60000); > > if (result == null) > > { > > logger.error(" Failed to fetch exported file URI "+ftpUri); > > throw new Exception("Failed to fetch from URI -"+ftpUri); > > } > > // the result is the response from the FTP consumer (the downloaded file) > > // replace the outher exchange with the content from the downloaded file > > exchange.getIn().setBody(result.getIn().getBody()); > > } > > catch(Throwable t) > > { > > exchange.setException(t); > > } > > finally > > { > > if (consumer != null) > > { > > consumer.stop(); > > consumer.shutdown(); > > } > > if (ftp != null) > > { > > ftp.stop(); //IMPORTANT TO REMOVE else next one will skip the file > > camelContext.removeEndpoints(ftpUri); > > } > > } > > } > > } > > ________________________________ > From: pontus.ullgren [via Camel] [mailto:[hidden email]] > Sent: Friday, August 10, 2012 5:39 AM > To: Vishal Changrani > Subject: Re: Consuming a remote FTP server triggered by a route in Camel 2.9 > > Hello V, > > It sound like you are looking for the content enricher (possibly the > pollEnricher) [1]. If I remember correctly, content enricher with file > or ftp uri, it has the limitation that this only polls one file at the > time and not an entire batch. > > If you are more interested in starting/stopping polling from a control > channel you can use a route policy[2] which a second control route > manipulates to start/stop. > A similar solution would be to implement a poll strategy [3][4] that > is controlled by messages on a separate control route. Returning false > from the begin method will stop the FTP endpoint from actually > polling. > > [1] http://camel.apache.org/content-enricher.html > [2] http://camel.apache.org/routepolicy.html > [3] http://camel.apache.org/polling-consumer.html > [4] http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/PollingConsumerPollStrategy.html > > Best regards > Pontus Ullgren > > On Tue, Aug 7, 2012 at 8:32 PM, vishal1981 > <[hidden email]> wrote: > >> Hi, >> In the older documentation for FTP component I found this, >> "Consuming a remote FTP server triggered by a route >> The FTP consumer is built as a scheduled consumer to be used in the from >> route. However if you want to start consuming from a FTP server triggered >> within a route it's a bit cumbersome to do this in Camel 1.x (we plan to >> improve this in Camel 2.x). However it's possible as this code below >> demonstrates." >> >> This is exactly what I want to do i.e. Consume on demand and not poll. >> But I cannot find any such improvement/support in 2.x. Was the support >> added? Am I missing something? >> >> Thanks in advance, >> V >> >> >> >> -- >> View this message in context: http://camel.465427.n5.nabble.com/Consuming-a-remote-FTP-server-triggered-by-a-route-in-Camel-2-9-tp5716940.html >> Sent from the Camel - Users mailing list archive at Nabble.com. > > > ________________________________ > If you reply to this email, your message will be added to the discussion below: > > NAML > > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/Consuming-a-remote-FTP-server-triggered-by-a-route-in-Camel-2-9-tp5716940p5717136.html > Sent from the Camel - Users mailing list archive at Nabble.com. ________________________________ If you reply to this email, your message will be added to the discussion below: http://camel.465427.n5.nabble.com/Consuming-a-remote-FTP-server-triggered-by-a-route-in-Camel-2-9-tp5716940p5717137.html To unsubscribe from Consuming a remote FTP server triggered by a route in Camel 2.9, click here. NAML -- View this message in context: http://camel.465427.n5.nabble.com/Consuming-a-remote-FTP-server-triggered-by-a-route-in-Camel-2-9-tp5716940p5717138.html Sent from the Camel - Users mailing list archive at Nabble.com. ------=_Part_15660_5114297.1344623093215--