首页 > 解决方案 > 如何在将文件发送到 sftp 出站适配器之前检查文件计数

问题描述

我有一个 file:inbound-channel-adapter 扫描文件系统上的 6 个文件,然后将文件传递给 int-sftp:outbound-channel-adapter 以将文件发送到 sftp 服务器。我想检查是否所有 6 个文件在源目录中都可用,然后才将它们全部复制到 sftp 服务器。很高兴将根据文件名编写一些条件以取消发送到 sftp 服务器。

我能想到的唯一解决方案是使用聚合器来计算目录中的文件,然后使用拆分器将它们转换回单个消息,然后将它们引导到出站通道适配器。但是对于一个简单的案例来说,这种方法似乎很重要。

有没有简单的替代方案。基本上它是关于发送一组消息,如果该组符合标准。

这是我的配置:

<bean id="fileFilterBean" class="org.springframework.integration.file.filters.SimplePatternFileListFilter">
    <constructor-arg value="*.DAT"></constructor-arg>
</bean>

<file:inbound-channel-adapter id="customerRelationChannelin" directory="file:${bwloan.outbound.sftp.ofsll.sharedFolder}" filter="fileFilterBean" >
    <int:poller cron="${bwloan.outbound.sftp.file.cron.expr}" max-messages-per-poll="50">
    </int:poller>
</file:inbound-channel-adapter>

<int:service-activator input-channel="customerRelationChannelin" output-channel="customerRelationChannelOut" ref="someHandler" />

<int-sftp:outbound-channel-adapter
            id="custRelFtpOutboundAdapter" channel="customerRelationChannelOut"
            remote-filename-generator-expression="payload.getName()"
            remote-directory="${myapp.outbound.sftp.remoteDirectory}"
            use-temporary-file-name="false"
            order="1" session-factory="custRelSftpSessionFactory"> 

</int-sftp:outbound-channel-adapter>

标签: spring-integration

解决方案


使用自定义 FileListFilter 过滤所有文件,直到出现 6 个文件。


推荐阅读