将轮询器添加到 SFTP 出站网关

Add Poller to SFTP Outbound Gateway

我不确定,但我无法将轮询器添加到我的 sftp 出站网关。我尝试这样做但我没有运气,它在启动期间不轮询所以我创建了一个服务接口然后通过调度程序调用该方法。有更好的方法吗?这是我所做的片段:

<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>

任何出站网关都是事件驱动的端点。它不是流程的开始,例如 <int-sftp:inbound-channel-adapter>.

如果真的想定期触发这样的网关,您可以通过“void”入站通道适配器来模拟它:

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

requestChannel不能再是队列通道。带有空负载的消息将在每次轮询时发送到此通道,您的网关将执行其逻辑。但是我看到您对远程目录使用 expression="payload" 来执行 LS 命令。因此,或者您需要配置 <int:inbound-channel-adapter > 以生成具有该远程目录有效负载的消息,或者只在网关上为其设置一个静态表达式,例如 expression="'/myRemoteDir'".

两种方式,但仅在流程开始时使用轮询通道适配器。否则不会定期触发网关。