How to stop polling spring sftp inbound adapter on file upload

I am trying to download a couple of text files from a remote server via SFTP using a java program. For this I am using Spring SFTP Integration Module and I have configured the inbound adapter as shown below.

 <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 everything works fine i.e. the files are uploaded correctly to the local directory, but the pool continues to work. I just want it to be one time. I do not want to constantly poll the remote directory. How can I stop polling as soon as the files are loaded ?. Basically I need some kind of event loading mechanism that I start manually and as soon as it loads the files it disables.

I also have a Spring associated gateway adapter, but it does the same thing. I will be very grateful for your help. Many thanks

+3


source to share


1 answer


I started the inbound adapter using the start () method. Next, a separate read channel was used to receive a message with the appropriate timeout. If no message is received within the timeout period, I stop the adapter using 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 is launched when the main class starts it. It downloads all files, waits for a new file until timeout expires, and stops.

0


source







All Articles