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. I have the following configuration for spring ftp inbound adapter

<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. 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?

Upvotes: 3

Views: 1399

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121590

Try to use FtpPersistentAcceptOnceFileListFilter instead of 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.

Not sure about again immediately since you use fixed-delay="300000".

The FtpInboundFileSynchronizer downloads all the matched files to local dir. And only after that the FtpInboundFileSynchronizingMessageSource starts to emits them as messages. Since you use there max-messages-per-poll="-1", all the local files will be sent during one polling cycle.

The new poll is started only after 300000 milliseconds.

Upvotes: 1

Related Questions