2015-06-20 25 views
3

我試圖從使用Java程序通過SFTP遠程服務器下載一對夫婦的文本文件。對於這個我使用Spring Integration的SFTP模塊,我已經如下配置的入站通道適配器。如何停止春季SFTP入站通道適配器輪詢當文件被下載

<int:channel id="recieveChannel"> 
     <int:queue /> 
    </int:channel> 

    <int-sftp:inbound-channel-adapter 
     session-factory="sftpSessionFactory" 
     local-directory="C:\test-outbound\" 
     channel="recieveChannel" 
     filename-regex=".*\.txt$"    
     remote-directory="/opt/IInsurer/messages/" 
     > 
     <int:poller fixed-rate="10000" receive-timeout="10000"></int:poller> 
    </int-sftp:inbound-channel-adapter> 

的問題是,每一件事情是工作的罰款,即文件被正確地下載到本地目錄,但彙集不斷going.I只是希望這是一個時間的事兒。不想連續輪詢遠程directory.How我可以輪詢停止一旦文件被下載?。基本上我需要的是某種事件驅動的下載機制,我手動觸發的,一旦它下載文件,它會關閉。

我也曾經跳出邊界網關適配器,但它確實在same.I會非常感謝你的help.Many感謝

+1

看看這是否有用http://stackoverflow.com/questions/11563469/spring-integration-cron-quartz-in-cluster/11564543#11564543 –

+0

Thanks.I確實偶然發現了你提供的鏈接,但是我沒有得到它。我沒有使用任何形式的批處理服務或任何東西。它是一個簡單的Java應用程序。我可以如何應用它 – Cheeta

+1

請檢查這是否會有所幫助.. http://stackoverflow.com/questions/23915524 /彈簧集成 - 手動啓停通道適配器,通過控制總線 –

回答

0

我用start()方法啓動的入站適配器。進一步使用一個單獨的頻道閱讀收到一個有關超時的消息。如果在超時期限內沒有收到消息,我使用stop()停止適配器。

適配器配置

<int-sftp:inbound-channel-adapter id="RemoteTestingInboundChannelAdapter" 
     channel="requestChannel" 
     session-factory="sftpSessionFactoryRemoteTesting" 
     local-directory="${sync.dir}" 
     remote-directory="${RemoteTesting.local.dir}" 
     auto-startup="false" 
     temporary-file-suffix=".writing" 
     filter = "compositeFilterRemoteTesting" 
     delete-remote-files="false"> 
     <int:poller fixed-rate="${RemoteTesting.poller}" max-messages-per-poll="${RemoteTesting.maxMessagesPerPoll}"/> 
    </int-sftp:inbound-channel-adapter> 

Main類

adapter.start(); 

QueueChannel localFileChannel = context.getBean("requestChannel", QueueChannel.class); 

Message<?> received = localFileChannel.receive(); 

while (received!=null) 
       received = localFileChannel.receive(timeOutPeriod); 
adapter.stop(); 

適配器開始時主類觸發它。它下載所有文件,等待新文件,直到超時然後停止。

相關問題