【问题标题】:Spring Integration Sftp Streaming Inbound Channel Adapter processing same file multiple timesSpring Integration Sftp Streaming Inbound Channel Adapter 多次处理同一个文件
【发布时间】:2018-08-07 12:57:55
【问题描述】:

我正在使用 spring 集成 sftp 入站流媒体通道适配器,它每隔几秒轮询一次。入站适配器选择同一个文件进行多次处理。下面是配置。

<int-sftp:inbound-streaming-channel-adapter id="ftpInbound"
        channel="ftpChannel"
        session-factory="sessionFactory"
        filter="filter"
        remote-file-separator="/"
        remote-directory="/sampleFolder" auto-startup="true">
    <int:poller fixed-rate="30000" max-messages-per-poll="1" />
</int-sftp:inbound-streaming-channel-adapter>



<int:stream-transformer id="withCharset" charset="UTF-8"
input-channel="ftpChannel" output-channel="outputChannel"/> 

<bean id="filter"
class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
    <list>
        <bean
            class="sample.CustomFilter">

</bean>
         <bean
class="org.springframework.integration.file.filters. 
AcceptOnceFileListFilter"/>
    </list>
</constructor-arg>

上面代码中的sample.CustomFilter 是SftpRegexPatternFileListFilter 的子类,其中我将accept 方法修改如下,根据Spring SFTP varying filename-regex 中的解决方案仅接受名称中包含当前日期的文件

public boolean accept(ChannelSftp.LsEntry file){
setPattern(new java.text.SimpleFormat("yyyyMMDD").format(new 
java.util.Date())+".txt$"
super.accept(file);
}

面临的问题是同一个文件正在处理多个文件。处理后文件将保留在同一远程目录中。我的过滤器配置是否有问题有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: spring spring-integration spring-integration-sftp


    【解决方案1】:

    AcceptOnceFileListFilter 基于对象哈希,同时SftpStreamingMessageSource 生成一个LsEntry,其中创建的每个新对象,即使具有相同的文件名也有自己的新哈希。

    您需要使用SftpPersistentAcceptOnceFileListFilter 来使其工作,它已经完成了您想要实现的目标。

    此外,我建议使用ChainFileListFilter 而不是CompositeFileListFilter。这样,如果文件没有通过CustomFilter,文件将不会到达SftpPersistentAcceptOnceFileListFilter。因此,我们根本不感兴趣的文件不会消耗额外的内存。

    在参考手册中查看更多信息:

    https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#sftp-inbound

    https://docs.spring.io/spring-integration/docs/5.0.7.RELEASE/reference/html/files.html#file-reading

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多