Apache camel file with doneFileName

2019-09-10 00:05发布

问题:

I am just starting to look at apache camel (Using blueprint routes) and I am already stuck.

I need to process a set of csv files with different formats. I get 5 files with foo_X_20160110.csv were X specifies the type of csv file and the files have a date stamp . These files can be quite large so a 'done' file is written once all files are written. The done file is named foo_trigger_20160110.csv.

I've seen the doneFileName option on file but that only supports a static name (I have a date in the filename) or it expects a done file for each input file.

The files have to be proceeded in a fixed order but it is not guaranteed in which order they are written to the input directory. Hence I need to wait for the done file.

Any idea how this can be done with Camel?

Any suggestions for good Camel books?

回答1:

Here is an example from the documentation http://camel.apache.org/file2.html

from("file:C:/temp/input.txt?doneFileName=done");

As you can see the doneFileName has a static value "done". But you can use standard java to write dynamic names i.e. for current dateformat or anything else and just use string operation to construct the URI. Hope that helps.

Update:

By the way, as mentioned in the documentation there is the option of dynamic placeholders for the doneFileName.

However its more common to have one done file per target file. This means there is a 1:1 correlation. To do this you must use dynamic placeholders in the doneFileName option. Currently Camel supports the following two dynamic tokens: file:name and file:name.noext which must be enclosed in ${ }. The consumer only supports the static part of the done file name as either prefix or suffix (not both).

from("file:bar?doneFileName=${file:name}.done");

You can also use a prefix for the done file, such as:

from("file:bar?doneFileName=ready-${file:name}");