【问题标题】:how to polling int:gateway to start int-ftp:outbound-gateway?如何轮询 int:gateway 以启动 int-ftp:outbound-gateway?
【发布时间】:2023-03-21 18:34:02
【问题描述】:

首先感谢关注
我定义出站网关 ftp 适配器在目标服务器上运行 ftp 命令,我的目标是定期在服务器上运行 ls,mv,get,... 命令并在批处理库作业上运行任务,我的代码是:

   <bean id="ftpClientFactory1" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
    <property name="host" value="127.0.0.1"/>
    <property name="port" value="21"/>
    <property name="username" value="banks_reader"/>
    <property name="password" value="123456"/>
    <property name="clientMode" value="2"/>
    <property name="fileType" value="2"/>

</bean>

<int:gateway id="gw" service-interface="ir.ali.util.ToFtpFlowGateway"
             default-request-channel="inbound1"/>
<int:channel id="inbound1"/>

<int-ftp:outbound-gateway id="gateway1"
                          session-factory="ftpClientFactory1"
                          request-channel="inbound1"
                          reply-channel="outbound"
                          reply-timeout="777"
                          auto-create-local-directory="false"
                          auto-startup="true"
                          filename-pattern="*"
                          remote-file-separator="/"
                          command="ls"
                          command-options="-dirs -R"
                          expression="payload"
                          mput-regex=".*"

        >
</int-ftp:outbound-gateway>
<int:channel id="outbound">
    <int:interceptors>
        <int:wire-tap channel="logger"/>
    </int:interceptors>
</int:channel>
<int:channel id="outboundJobRequestChannel"/>
<int:logging-channel-adapter id="logger" log-full-message="true" />

<int:transformer input-channel="outbound"  output-channel="outboundJobRequestChannel">
    <bean class="ir.ali.configuration.FileMessageToJobRequest"/>
</int:transformer>

<int:splitter id="splitter" input-channel="outbound" output-channel="ftpChannel"/>

<int:channel id="ftpChannel">
    <int:queue/>
</int:channel>

在应用程序类中向inbound1频道发送消息并启动int-ftp:outbound-gateway,代码为:

 final ToFtpFlowGateway toFtpFlow = ctx.getBean(ToFtpFlowGateway.class);
    try  {
        List<Boolean> rmResults = toFtpFlow.lsGetAndRmFiles("/");
    } catch (Exception e) {
        e.printStackTrace();
    }

它工作正常,问题是我需要在服务器上运行定期 ls 和 mv ,...递归命令,如何定期运行toFtpFlow.lsGetAndRmFiles("/"); 来启动int-ftp:outbound-gateway

【问题讨论】:

    标签: spring ftp spring-integration


    【解决方案1】:
    <int:inbound-channel-adapter expression="/" channel="inbound1">
        <int:poller fixed=delay="60000" />
    </int:inbound-channel-adapter>
    
    <int:channel id="inbound1"/>
    
    <int-ftp:outbound-gateway id="gateway1"
                          session-factory="ftpClientFactory1"
                          request-channel="inbound1"
                          reply-channel="outbound"
                          reply-timeout="777"
                          auto-create-local-directory="false"
                          auto-startup="true"
                          filename-pattern="*"
                          remote-file-separator="/"
                          command="ls"
                          command-options="-dirs -R"
                          expression="payload"
                          mput-regex=".*"/>
    

    【讨论】:

    • 感谢 @gary Russell,我需要在 ftp 服务器上运行递归 ls 命令,但 int:inbound-channel-adapter 不支持 :(
    • 不 - 你误会了 - 这不是一个 ftp 入站通道适配器,只是一个简单的入站通道适配器,它将每 60 秒向inbound1 发送一个有效负载为/ 的消息。 ftp 网关会收到它,就像你的 ToFtpFlowGateway 一样。
    • 成功了 :) @gary 谢谢,这两天我参与了这个问题。我希望永远成功。
    猜你喜欢
    • 2023-04-08
    • 1970-01-01
    • 2016-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多