Search code examples
apache-camelspring-camel

Processing only modified files using apache camel


I have got new requirement to be implemented using apache camel.

  1. process the file without moving it
  2. process the file only if it is modified
  3. it is okay to process same file again
  4. it shouldn't process new file.

As I am new to Apache Camel, I explored feature of file component and got some example and able to achieve first 3 points using below code.

from("file:C://inputFolder?idempotentKey=${file:name}-${file:modified}&noop=true")
    .to("file:C://outputFolder");

However unable to achieve the 4th point. Above code picks up the new file which being just created (Meaning created date and modified date is being same).

Could someone help me to achieve the 4th point (i.e. it should not pick up new file in that directory)


Solution

  • There is no way to look at the time the file was created in Camel as I can see. Possible workaround here is to use renaming approach along with the antInclude option, e.g.

    from("file:C://inputFolder?idempotentKey=${file:name}-${file:modified}&noop=true&antInclude=*.modified")
        .to("file:C://outputFolder");
    

    In this case new file need to be created with another extension, such as myfile.created, and then renamed to myfile.modified after it was modified for the first time