How to throw an Exception if file on ftp is locked? Spring DSL

386 views Asked by At

My route is polling from endpoint ftp://localhost:21/folder?username=user&password=password&delay=15s&move=processed&moveFailed=error&sendEmptyMessageWhenIdle=true&passiveMode=true. If I just add readLock=rename, Camel will ignore troublesome file and leave it in folder.

How to implement camel behavior so that if file is still being locked by somebody after readLockTimeout or n attempts, Camel will not skip the file, but throw an Exception.

1

There are 1 answers

0
Ahmad Y. Saleh On BEST ANSWER

I guess this can be established by implementing a custom ReadLockStrategy (the interface is GenericFileExclusiveReadLockStrategy)

You can set the custom strategy using the option exclusiveReadLockStrategy (see File2 component options).

P.S. Maybe its best to override one of the strategies provided out of the box, FileLockExclusiveReadLockStrategy for instance. All you need then is to override the acquireExclusiveReadLock() method to throw an exception when its super returns false.