简体   繁体   English

Spring ftp集成。 处理后删除文件

[英]Spring ftp integration. Delete files after processing

I need to download files through ftp every 5 minutes to local directory, process each of them and then remove from local directory. 我需要每隔5分钟通过ftp将文件下载到本地目录,处理每个文件然后从本地目录中删除。 I have the following configuration for spring ftp inbound adapter 我有弹簧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 provides getting only files that were created on the remote directory for the last five minutes only. CustomFilter仅提供仅在过去五分钟内在远程目录中创建的文件。 It looks like it first downloads files, parses them, removes and then downloads those same files again immediately after service activator finishes its jobs. 看起来它首先下载文件,解析它们,删除然后在服务激活器完成其作业后立即再次下载这些相同的文件。 How to you stop file pulling after service finishes parsing them. 如何在服务完成解析后停止文件拉取。 Or any other ideas? 还是其他任何想法?

Try to use FtpPersistentAcceptOnceFileListFilter instead of AcceptOnceFileListFilter . 尝试使用FtpPersistentAcceptOnceFileListFilter而不是AcceptOnceFileListFilter

Since FTPFile doesn't implement equals() and hashCode() , the if (this.seenSet.contains(file)) { operation fails and we consider that file as new one and proceed. 由于FTPFile没有实现equals()hashCode() ,因此if (this.seenSet.contains(file)) {操作失败,我们将该文件视为新文件并继续。

Not sure about again immediately since you use fixed-delay="300000" . 由于您使用fixed-delay="300000"不能again immediately确定。

The FtpInboundFileSynchronizer downloads all the matched files to local dir. FtpInboundFileSynchronizer将所有匹配的文件下载到本地目录。 And only after that the FtpInboundFileSynchronizingMessageSource starts to emits them as messages. 只有在那之后, FtpInboundFileSynchronizingMessageSource开始将它们作为消息发出。 Since you use there max-messages-per-poll="-1" , all the local files will be sent during one polling cycle. 由于你在那里使用max-messages-per-poll="-1" ,所有本地文件将在一个轮询周期内发送。

The new poll is started only after 300000 milliseconds. 新轮询仅在300000毫秒后启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM