Reputation: 2049
I am using a Camel route (R) to copy files from A to B. But this is event based i.e. there is route R1 which polls a directory (C) and when any file found, its processor triggers R to copy files then suspend R.
I would like to ensure, that while suspending all the existing files in A are copied to B, then only I will suspend. But any shutdown strategy (don't know if this is honored while suspension also) ensures only the on-fly message to be process i.e. only current file (on which R is working on currently) will be copied to B before R is suspended. But I want all present files must be copied to B.
How can I ensure that.
Constraints:
Thanks, Abhishek
Upvotes: 0
Views: 146
Reputation: 7636
Sometimes, it is easier to use the good old Java stack we used in the "pre-Camel" era. That said, do the file copy on your own in a separate Processor
(or a Camel unware bean):
@Override
public void process(final Exchange exchange) throws Exception {
final File source = new File("/path/to/in-directory");
final File desc = new File("/path/to/out-directory");
org.apache.commons.io.FileUtils.copyDirectory(source, desc);
}
For the file copy, the org.apache.commons.io.FileUtils
from the Apache Commons project is used.
EDIT:
As @Petter correctly noted, with this solution, there is no need to create and start a separate route that has to be shutdown again. The directory copy processor could just be added to the R1
processor where the copying is triggered.
Upvotes: 1
Reputation: 22279
Is this even a problem?
Given you have a OnCompletion in the route that counts the number of messages in the folder and if there is no files, then shutdown the route.
Upvotes: 0