J Doe J Doe - 1 year ago 223
Java Question

Spring integration SFTP - Post Transfer processing

I have successfully set up Spring with SFTP integration, and am polling an SFTP server and pulling down files.

What I would like to know, is it possible for a task to be fired on each file once it's download has completed? I don't want to go down the road of filesystem watches - is there something built into Spring SFTP for this?

Having looked at the documentation, it looks like it can be achieved with Channels.

This is what my receiver channel currently looks like:

<int:channel id="receiveChannel">
<int:queue />

I'm not sure what I need to do to fire a customer interceptor or similar.

Edit: from the Spring docs it says this:

It is also important to understand that SFTP Inbound Channel Adapter is a Polling Consumer and therefore you must configure a poller (either a global default or a local sub-element). Once the file has been transferred to a local directory, a Message with java.io.File as its payload type will be generated and sent to the channel identified by the channel attribute.

I'm not sure how to implement this - and can't find any examples.

Answer Source

Looks like you have to start from the beginning of Enterprise Integration Patterns and determine for yourself that channel is the most important first class citizen in the integration.

So, you have an <int-sftp:inbound-channel-adapter>, which responsibility to poll entities from the remote directory, turn them to the java.io.File (like you noticed in the RTFM) and send as a payload of Message to the configured channel. The subscriber for that channel will pick up the message and do some desired process under that File payload.

See also Spring Integration Samples for more information.