Search code examples
springspring-integrationsftp

Add Poller to SFTP Outbound Gateway


I'm not sure but I can't add a poller to my sftp outbound gateway. I tried doing it but I have no luck, it does not poll during start up so I have created a service interface and then just call the method via scheduler. Is there a better way to do it? Here is snippet of what I did :

<int:channel channel="requestChannel"
    <int:queue />
</int:channel>

<int-sftp:outbound-gateway id="ls"
    auto-startup="true"
    expression="payload"
    request-channel="requestChannel"
    remote-directory="${remote-directory}"
    command-options="-1"
    session-factory="sftpSessionFactory"
    command="ls"
    reply-channel="replyChannel">
    <int:poller fixed-delay="10000" max-messages-per-poll="1"/>
</int-sftp:outbound-gateway>

Solution

  • Any Outbound Gateway is an event-driven endpoint. It is not a beginning of the flow like it would be, for example, with the <int-sftp:inbound-channel-adapter>.

    If really would like to trigger such a gateway in a periodic manner, you would simulate it via "void" inbound channel adapter:

    <int:inbound-channel-adapter channel="requestChannel" expression="''">
         <int:poller fixed-delay="10000" max-messages-per-poll="1"/>
    </int:inbound-channel-adapter>
    

    The requestChannel must not be a queue channel any more. The message with empty payload is going to be sent to this channel on each poll and your gateway is going to perform its logic. However I see that you use expression="payload" for the remote directory to perform LS command. So, or you need to configure that <int:inbound-channel-adapter > to produce a message with that remote dir payload or just have a static expression for it on the gateway, e.g. expression="'/myRemoteDir'".

    Either way, but only with a polling channel adapter in the beginning of the flow. Otherwise a gateway is not going to be triggered periodically.