[英]How to stop spring sftp inbound channel adapter polling when files are downloaded
I am trying to download a couple of text files from a remote server via SFTP using a java program. 我试图通过SFTP使用java程序从远程服务器下载几个文本文件。 For this I am using Spring Integration SFTP module and I have configured an Inbound Channel Adapter as below. 为此我使用Spring Integration 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>
The problem is that every thing is working fine ie the files are downloaded correctly to the local directory but the pooling keeps on going.I just want this to be a one time thing.I don't want to continuously poll the remote directory.How can I make the polling stop once the files are download?.Basically what I need is some sort of an event driven download mechanism which I manually trigger and once it downloads the files it shuts down. 问题是每个东西都工作得很好,即文件正确下载到本地目录,但池继续运行。我只是希望这是一次性的事情。我不想连续轮询远程目录。如何我可以在下载文件后停止轮询吗?。基本上我需要的是某种事件驱动的下载机制,我手动触发它,一旦下载它关闭的文件。
I have also spring out bound gateway adapter but it does the same.I will really appreciate your help.Many Thanks 我也弹出绑定的网关适配器,但它也一样。我将非常感谢你的帮助。很多谢谢
I started the inbound adapter using start() method. 我使用start()方法启动了入站适配器。 Further used a separate channel to read receive a message with a relevant timeout. 进一步使用单独的通道来读取接收具有相关超时的消息。 If no message is received within the timeout period, I stop the adapter using stop(). 如果在超时期限内没有收到任何消息,我使用stop()停止适配器。
Adapter configuration 适配器配置
<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 class 主要课程
adapter.start();
QueueChannel localFileChannel = context.getBean("requestChannel", QueueChannel.class);
Message<?> received = localFileChannel.receive();
while (received!=null)
received = localFileChannel.receive(timeOutPeriod);
adapter.stop();
The adapter starts when main class fires it. 适配器在主类触发时启动。 It downloads all files, waits for new file till the timeout then stops. 它会下载所有文件,等待新文件,直到超时然后停止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.