In Apache Camel xml I want to process a each file in a directory recursively when a certain file indicates that all files have been successfully generated (@see mock:result). When all files have been processed I want to do some cleanup (@see mock:finished)
1st try
What I wanted is basically something like this:
<route id="test1">
<from uri="file://target/test-classes/generated?recursive=true&doneFileName=./done-generation.txt"/>
<to uri="mock:result"/>
<choice>
<when>
<simple>${exchangeProperty.CamelBatchComplete}</simple>
<to uri="mock:finished"/>
</when>
</choice>
</route>
This solution doesn’t work as I expected. It only returns the files in the same directory as the done-generation file. (It would work if I remove the doneFileName option but obviously this doesn’t wait for the files to be fully generated)
2nd try
After a lot of tries the closest I got to work was this:
<route id="testSimples">
<!--<from uri="file://target/test-classes/generated?fileName=done-generation.txt"/>-->
<from uri="scheduler:mockScheduler?delay=10000?"/>
<setBody>
<simple resultType="Integer">-1</simple>
</setBody>
<loop doWhile="true" >
<simple>${body} != null</simple>
<setBody>
<simple >${null}</simple>
</setBody>
<pollEnrich timeout="1" aggregationStrategy="groupedMessageAggregationStrategy">
<constant>file://target/test-classes/generated?repeatCount=1&noop=true&recursive=true&initialDelay=0&antExclude=gen/></constant>
</pollEnrich>
</loop>
<split aggregationStrategy="groupedMessageAggregationStrategy2">
<simple>${exchangeProperty.CamelGroupedExchange}</simple>
<to uri="mock:result"/>
</split>
<to uri="mock:finished"/>
</route>
But this solution only works with an inital consumer not being file. (scheduler in this case) as soon as I change to scheduler it only returns one time the done-generation file instead of all the files
Would anybody have a hint on how to achieve what I want? I would prefer an option in pure xml but if some additional processors are needed that would also be fine.