This is my route
from("sftp://userName:password@ip:22/<my-folder>?move=.done")
.routeId("my-route-1")
.<processing-logic>
How to avoid processing the same files incase of multiple instances?
?move=.done") .routeId("my-route-1") . This is my route How to avoid processing the same files incase of multiple instances? You can use File Based Idempotent Repository. Using a file based idempotent repository Here my example; After this configuration you have to add these parameters to your SFTP router. It will store files read from SFTP in an idempotent file (filename + file size) and will prevent the same file from being processed again. You can change the idempotentKey value according to your needs.
Camel SFTP how to prevent processing the same file incase of multiple nodes?
161 Views
Asked by
dark ninja
At
from("sftp://userName:password@ip:22/<my-folder>?move=.done")
.routeId("my-route-1")
.<processing-logic>
There are 2 best solutions below
On
FileIdempotentRepository sftpIdempotentRepository = new FileIdempotentRepository();
sftpIdempotentRepository.setFileStore(new File("where to store it"));
exchange.getContext().getRegistry().bind("sftpIdempotentRepository", sftpIdempotentRepository);
from("sftp://userName:password@ip:22/<my-folder>?move=.done&idempotent=true&idempotentKey=${file:name}-${file:size}&idempotentRepository=#sftpIdempotentRepository")
.routeId("my-route-1")
.<processing-logic>
Camel recently introduced some interesting clustering capabilities - see here.
In your particular case, you could model a route which is taking the leadership when starting the directory polling, preventing thereby other nodes from picking the (same or other) files.
Set it up is very easy, and all you need is to prefix singleton endpoints according to the master component syntax: master:namespace:delegateUri
This would result in something like this: