2010-12-21

Camel 2.6 - Using done files with file/ftp components

The upcoming 2.6 release of Apache Camel now supports using "done files" with the file/ftp components. The "done file" is a marker file which signals that the target file is ready for the consumer. You can use this when exchanging data using files and want to avoid the consumer to pickup the target file before its ready (= done).

Mind that Camel also has a number of other features
for detecting if a file is ready,
 which you can read about the readLock option.

For example if write a file with the name yyyyMMdd-report.txt and want to write a done file using the syntax file name .done, then you can do as follows:

.to("file:reports?fileName=${date:now:yyyMMdd}-report.txt&doneFileName=${file:name}.done");

Notice the new doneFileName option where we define the pattern of done file. It supports two dynamic placeholders which is ${file:name} and ${file:name.noext}. The latter is the file name without the extension.

The "done file" must be located in the same directory as the target file.

On the consumer side we can do as follows:

from("file:reports?doneFileName=${file:name}.done")
    .to("bean:fileService");

Which tells Camel to only pickup files if a done file exists with that given name pattern.

And all this works as well with the FTP components.

5 comments:

chermonder said...

Hello.
Does it possible to not remove "done" file after exchange?

chermonder said...

Hello.
Does it possible to not remove done file after exchange?

chermonder said...

Does it possible to not remove done file after exchange?

Claus Ibsen said...

No the done file is automatic deleted AFAIR. Fell free to request for an enhancement at the Apache Camel project. Read more here: http://camel.apache.org/support

chermonder said...

Thank you for your answer.