I currently have the following camel route:
//Only continue to next route if success
from("file:///tmp/camel/input")
.routeId("Test Route")
.to("file:///tmp/camel/test")
.onCompletion().onCompleteOnly()
.log("Success for file: ${header.CamelFileName}")
.setHeader("recipientList", constant("file:///tmp/camel/output, file:///tmp/camel/output2"))
.recipientList(header("recipientList"))
.end();
Need to send a file to recipients only if the previous route was successful.
However, while running the route I came to the conclusion that the .to in the onCompletion() block also reads from the input folder, but the files are already gone, so it can't pick them up and write them to the recipients. (I can't set noop=true at the from, since I do want the files gone after sending them to the recipients...)
So how would we route the file to the recipients, having a successful previous route as prerequisite?
This will work
from("file:///tmp/camel/input")
.routeId("Test Route")
.to("file:///tmp/camel/test?noop=true")
.onCompletion().onCompleteOnly()
.log("Success for file: ${header.CamelFileName}")
.end();
from("file:///tmp/camel/test?noop=true")
.to("file:///tmp/camel/output")
.to("file:///tmp/camel/output2");
I feel OnCompletion
is redundant here, since the second route will not trigger, if the file transfer to /camel/test
is failed.
Another point is you can make use of move=.done
option just to make sure, that the second route doesn't start before the full file is transferd
from("file:///tmp/camel/test?noop=true&move=.done")
.to("file:///tmp/camel/output")
.to("file:///tmp/camel/output2")