Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

spring - 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>
question from:https://stackoverflow.com/questions/65905466/add-poller-to-sftp-outbound-gateway

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...