What would be the best way of stopping a Spring Integration application after it has processed all messages that resulted from a series of FTP Outbound Gateway ls commands?
As a one-off job I need to traverse an FTP directory structure, recursing for each directory found, and copy down each file and then send it on as message for processing. Once the FTP directory tree has been fully traversed, and all the messages that resulted from the traversal have been processed, I'd like to stop the application gracefully.
My current thoughts are that I could try and keep a track of the activity of the gateway and all queues, and when they've all had a size of 0 for a while, terminate the application. This could be made more sophisticated by doing something like keeping a count of all files for each directory (this'd require extending AbstractRemoteFileOutboundGateway), making sure the directory name stays on all message headers through the flow, and then having a downstream component that keeps a count of messages processed for each directory, and initiates shutdown once they've all been accounted for.
That sounds like a fair amount of work - does anyone know of a simpler way? I've got a choice between writing the app without Spring Integration and doing a load of tedious stuff by hand (iterating of FTP trees, copying files about), or using Spring Integration but instead having to extend bits of it to match my use case.