xlogger
xlogger

Reputation: 119

Apache Camel Batch FTP Upload then disconnect

My use case is to poll a local directory for a list of new files periodically, and then upload them to a FTP server in 1 connection. The Camel route is defined in Spring XML as follows:

<route>
  <from uri="file:data/inbox?noop=true&amp;delay=1000&amp;maxMessagesPerPoll=3" />
  <to uri="ftp:uid:xxxxx@host:21/data?disconnect=false"/>
</route>

The route is functioning well, except that the FTP connection will retain connected until the FTP server timeout my connection. I hope to reuse the same connection to upload a batch of files and then close the connection immediately when the last file in the batch completed the upload. How can achieve this in Camel?

Upvotes: 0

Views: 1064

Answers (2)

Souciance Eqdam Rashti
Souciance Eqdam Rashti

Reputation: 3191

There might be a way but it is not pretty.

You could try to wrap your route based on a cronSchedulePolicy. So say you kick start the route once every hour and poll the directory and send the files. Then you simply add a stop(). Not sure if the stop is exactly the same in the xml dsl. Alternatively, you could also write that onExchangeComplete(new Processor(StopProcessor(routeId)) and inside that processor you via exchange.getContext.stopRoute(routeid) stop the route. Again this depends on your requirements allow you to do this.

<route>
  <from uri="file:data/inbox?noop=true&amp;delay=1000&amp;maxMessagesPerPoll=3" />
  <to uri="ftp:uid:xxxxx@host:21/data?disconnect=false"/>
<stop/>
</route>

Upvotes: 0

Claus Ibsen
Claus Ibsen

Reputation: 55540

This is not possible currently. You will need to write some code to do the disconnect yourself.

You are welcome to log a JIRA to enhance this in camel-ftp: https://issues.apache.org/activemq/browse/CAMEL. For example a new option to disconnectOnBatchComplete.

Upvotes: 2

Related Questions