Spring 集成 SFTP - Post 传输处理

Spring integration SFTP - Post Transfer processing

我已成功设置 Spring 与 SFTP 集成,正在轮询 SFTP 服务器并下载文件。

我想知道,是否可以在每个文件下载完成后触发任务?我不想走文件系统监视的道路 - Spring SFTP 中是否内置了一些东西?

看了文档,好像可以用Channels来实现。

这是我的接收频道目前的样子:

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

我不确定我需要做什么来触发客户拦截器或类似的东西。

编辑:Spring 文档中这样说:

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.

我不确定如何实现这个 - 也找不到任何示例。

看来你必须从 Enterprise Integration Patterns 开始,并自己确定 channel 是整合中最重要的第一个 class 公民。

所以,你有一个 <int-sftp:inbound-channel-adapter>,负责 轮询 远程目录中的实体,将它们转到 java.io.File(就像你在RTFM)并作为 Messagepayload 发送到配置的频道。该频道的订阅者将接收消息并在 File payload.

下执行一些所需的过程

另请参阅 Spring Integration Samples 了解更多信息。

为了遇到此问题的其他人的利益,问题是仅当 ALL 文件已传输后,消息才会放在接收频道上。他们不是一次处理一个(正如我所预料的那样)。在我的例子中,我在远程 SFTP 服务器上有数千个大文件,只有在所有文件都下载后,消息才会发送到接收方通道。

我不确定这是否是设计使然。