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+s465427n5717137...@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]</user/SendEmail.jtp?type=node&node=5717137&i=0>> 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]</user/SendEmail.jtp?type=node&node=5717137&i=1>] > 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]</user/SendEmail.jtp?type=node&node=5717117&i=0>> 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<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.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<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5716940&code=dmlzaGFsLmNoYW5ncmFuaUBlcmljc3Nvbi5jb218NTcxNjk0MHwxNTgwMjU0NDcx>. NAML<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.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.