简体   繁体   English

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

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

相关问题 春季整合sftp:inbound-channel-adapter delete-remote-files = false - spring integration sftp:inbound-channel-adapter delete-remote-files=false Spring Integration轮询多台服务器上的入站通道适配器 - Spring Integration polling inbound-channel-adapter on multiple servers Spring Integration和RabbitMQ,如何避免对入站通道适配器进行轮询 - Spring Integration and RabbitMQ, how can I avoid polling on my inbound channel adapter Spring SFTP入站适配器出现问题 - Problems with spring sftp inbound adapter 使用Spring Integration for Inbound Adapter时如何检查SFTP连接是否成功 - How to check whether the SFTP connection is successful or not when using Spring Integration for Inbound Adapter Spring入站通道适配器-如何自动删除10天以上的文件夹和文件 - Spring inbound channel adapter - how to auto delete folders and files older than 10 days 使用Spring Integration入站通道适配器时重新下载消息 - Re downloading of message when using spring integration inbound channel adapter 为什么SFTP入站/出站通道适配器有单独的通道声明,为什么没有简单文件入站/出站通道适配器的通道声明? - Why there is separate channel declaration for SFTP inbound/outbound channel adapter and why not for simple file inbound/outbound channel adapter? Spring Integration SFTP通道适配器未将消息发送到下游服务激活器以进行第二次轮询 - Spring Integration SFTP channel adapter not sending the message to the down stream service activator for the second polling 使用int-sftp:inbound-channel-adapter时重新读取文件 - Re Read file when using int-sftp:inbound-channel-adapter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM