![](/img/trans.png)
[英]spring integration sftp:inbound-channel-adapter delete-remote-files=false
[英]How to stop spring sftp inbound channel adapter polling when files are downloaded
我試圖通過SFTP使用java程序從遠程服務器下載幾個文本文件。 為此我使用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>
問題是每個東西都工作得很好,即文件正確下載到本地目錄,但池繼續運行。我只是希望這是一次性的事情。我不想連續輪詢遠程目錄。如何我可以在下載文件后停止輪詢嗎?。基本上我需要的是某種事件驅動的下載機制,我手動觸發它,一旦下載它關閉的文件。
我也彈出綁定的網關適配器,但它也一樣。我將非常感謝你的幫助。很多謝謝
我使用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>
主要課程
adapter.start();
QueueChannel localFileChannel = context.getBean("requestChannel", QueueChannel.class);
Message<?> received = localFileChannel.receive();
while (received!=null)
received = localFileChannel.receive(timeOutPeriod);
adapter.stop();
適配器在主類觸發時啟動。 它會下載所有文件,等待新文件,直到超時然后停止。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.