2015-06-20 104 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(); 

适配器开始时主类触发它。它下载所有文件,等待新文件,直到超时然后停止。

相关问题