【问题标题】:Spring ftp integration. Delete files after processingSpring ftp 集成。处理后删除文件
【发布时间】:2017-02-26 18:13:02
【问题描述】:

我需要每 5 分钟通过 ftp 将文件下载到本地目录,处理每个文件,然后从本地目录中删除。 我对 spring ftp 入站适配器有以下配置

<int-ftp:inbound-channel-adapter
        id="ftpPortAdapter"
    channel="receiveChannel"
    session-factory="ftpSessionFactory"
    local-directory="/test"
    local-filename-generator-expression="#this"
    remote-directory="/prod"
    auto-create-local-directory="true"
    delete-remote-files="false"
    filter="compositeFilter">
    <int:poller fixed-delay="300000" max-messages-per-poll="-1"/>
</int-ftp:inbound-channel-adapter>

<bean id="compositeFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
    <constructor-arg>
        <list>
            <bean class="org.springframework.integration.file.filters.AcceptOnceFileListFilter"/>
            <bean id="customFilter"
                class="ru.lanit.parkomats.integration.impl.dozor.MyInboundChannelFilter">
                <property name="initDate" value="2016-10-12 00:00:00"/>
            </bean>
        </list>
    </constructor-arg>
</bean>

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

<int:service-activator input-channel="receiveChannel" ref="ftpFileService" method="processNewFiles">
    <int:request-handler-advice-chain>
        <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
            <property name="onSuccessExpression" value="payload.delete()"/>
            <property name="onFailureExpression" value="payload.delete()"/>
        </bean>
    </int:request-handler-advice-chain>
</int:service-activator>

CustomFilter 仅提供仅获取最近五分钟在远程目录上创建的文件。看起来它首先下载文件,解析它们,删除然后在服务激活器完成其工作后立即再次下载相同的文件。 服务完成解析后如何停止文件拉取。还是有其他想法?

【问题讨论】:

    标签: java spring ftp spring-integration


    【解决方案1】:

    尝试使用FtpPersistentAcceptOnceFileListFilter 而不是AcceptOnceFileListFilter

    由于FTPFile 没有实现equals()hashCode()if (this.seenSet.contains(file)) { 操作失败,我们将该文件视为新文件并继续。

    不确定again immediately,因为您使用的是fixed-delay="300000"

    FtpInboundFileSynchronizer 将所有匹配的文件下载到本地目录。只有在那之后,FtpInboundFileSynchronizingMessageSource 才开始将它们作为消息发出。由于您在那里使用max-messages-per-poll="-1",所有本地文件将在一个轮询周期内发送。

    新的轮询仅在300000 毫秒后开始。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-15
      • 2019-03-17
      • 2017-07-03
      • 1970-01-01
      • 2018-01-31
      相关资源
      最近更新 更多