Abhishek Chatterjee
Abhishek Chatterjee

Reputation: 2049

Camel suspension strategy

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:

  1. Route R must be event based, when only an event comes then only it will copy existing log file from A to B, then it will go to sleep untill next event comes
  2. If R is made event based and since A is a log folder where all the logs reside, I can not copy all the logs every-time...a huge size
  3. I can not delete files from A after copying

Thanks, Abhishek

Upvotes: 0

Views: 146

Answers (2)

Peter Keller
Peter Keller

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

Petter Nordlander
Petter Nordlander

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

Related Questions