如何在Spring Integration with FTP中设置轮询配置(轮询FTP服务器)

时间:2016-07-14 10:39:13

标签: ftp spring-integration

我正在编写一个连接到FTP服务器的应用程序,以便将文件传输到我的本地机器。为此,我正在使用入站通道适配器。一旦启动应用程序,我看到所有相关文件都已转移从FTP服务器到我的本地目录,直到所有文件最终同步到达时间(FTP服务器和本地文件上的文件数相同)。我现在想要每隔5分钟轮询一次FTP服务器以检查是否存在任何新文件。我最初认为它将是“固定速率”字段,但它似乎每隔3秒轮询到FTP服务器。我遗漏了一些东西这里吗?

我的配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:int="http://www.springframework.org/schema/integration"
       xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd">

    <context:property-placeholder location="classpath:application.properties"/>

    <bean id="ftpSessionFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
        <property name="host" value="${ftp.host}"/>
        <property name="port" value="${ftp.port}"/>
        <property name="username" value="${ftp.username}"/>
        <property name="password" value="${ftp.password}"/>
    </bean>

    <int-ftp:inbound-channel-adapter id="ftpInbound"
                                     channel="ftpChannel"
                                     session-factory="ftpSessionFactory"
                                     filename-pattern="*.xml"
                                     auto-create-local-directory="true"
                                     delete-remote-files="false"
                                     remote-directory="/"
                                     local-directory="ftp-inbound"
                                     local-filter="acceptOnceFilter">

        <int:poller fixed-rate="10000" max-messages-per-poll="-1">
            <int:transactional synchronization-factory="syncFactory" />
        </int:poller>

    </int-ftp:inbound-channel-adapter>

    <bean id="acceptOnceFilter"
          class="org.springframework.integration.file.filters.AcceptOnceFileListFilter" />

    <int:transaction-synchronization-factory id="syncFactory">
        <int:after-rollback expression="@acceptOnceFilter.remove(payload)" />
    </int:transaction-synchronization-factory>

    <bean id="transactionManager"
          class="org.springframework.integration.transaction.PseudoTransactionManager" />

    <int:channel id="ftpChannel">
        <int:queue/>
    </int:channel>
</beans>

1 个答案:

答案 0 :(得分:2)

你有fixed-rate="10000"所以它会每10秒轮询一次。固定费率是指每10秒;如果下载需要7秒钟,我们将在3中再次轮询,然后是10,10,10 ......直到新文件到达。

fixed-delay表示下一个轮询在最后一个轮询结束后的毫秒数开始。

如果要在找不到更多文件时更改轮询率,可以使用智能轮询器documentation here

为方便起见,提供了SimpleActiveIdleMessageSourceAdvice,如该文档中所述。