2016-07-14 112 views
0

我正在編寫一個應用程序來連接到FTP服務器以將文件傳輸到本地計算機。爲此,我使用入站通道適配器。一旦啓動應用程序,我發現所有相關文件都從FTP服務器傳輸到本地目錄,直到所有文件最終同步時(在FTP服務器和本地文件中的文件數相同)。我現在想每5分鐘輪詢一次FTP服務器以檢查是否存在任何新文件。我最初認爲這將是「固定速率」字段,但它似乎每3秒向FTP服務器輪詢一次。我錯過了一些東西這裏?在Spring中如何設置輪詢配置(輪詢FTP服務器)與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> 

回答

2

你有fixed-rate="10000"所以它會每10秒輪詢。固定利率意味着每10秒;如果下載需要7秒鐘,我們將再次輪詢3,然後10,10,10 ...直到新文件到達。

fixed-delay表示下一次輪詢在最後一輪結束後的毫秒數開始。

如果您希望在找不到更多文件時更改輪詢速率,則可以使用智能輪詢器documentation here

爲方便起見,提供了SimpleActiveIdleMessageSourceAdvice,如該文檔中所述。