繁体   English   中英

如何在下载文件时停止spring sftp入站通道适配器轮询

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM