【问题标题】:Use Spring Integration FTP client without the poller使用没有轮询器的 Spring Integration FTP 客户端
【发布时间】:2015-09-24 02:15:40
【问题描述】:

希望有人能帮我解决这个问题...

我们有以下用例:根据请求,连接到远程 FTP 服务器,尝试最多 3 次下载文件(其名称和路径由调用者提供)。断开与远程 FTP 服务器的连接。等待下一个请求。

由于 Spring 框架不提供 FTP 客户端解决方案,我们为此使用 Spring Integration。我们遇到的问题是 FTP 入站通道适配器需要设置轮询器,它会不断地轮询远程服务器。在我们的例子中,我们只需要轮询 3 次然后断开连接。然后等待下一个请求等等。

有没有办法通过 Spring Integration 做到这一点?我们还有哪些其他选择?

【问题讨论】:

    标签: spring ftp spring-integration ftp-client


    【解决方案1】:

    Spring Integration FTP 模块为您的案例提供了<int-ftp:outbound-gateway>GET 命令。另外,在<request-handler-advice-chain>RequestHandlerRetryAdvice 面前,还有一个开箱即用的retry 支持。

    请参阅 Spring Integration 参考手册了解更多信息。

    【讨论】:

    • 谢谢你,阿尔乔姆。使用 ftp:outbound-gateway 确实解决了我们在从 FTP 服务器获取文件时不使用轮询器的问题。将在答案部分提供有关实际解决方案的更多详细信息。
    【解决方案2】:

    感谢 Artem 为我指明了正确的方向。发现这个link 很有帮助。

    这是从从 FTP 服务器下载 a.txt 文件的链接中获取的修改后的 FtpOutboundGatewaySample-context.xml。请注意,出于性能原因,它不执行 LS 和 RM 命令(仅 MGET):

    <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:int="http://www.springframework.org/schema/integration"
            xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
            xsi:schemaLocation="http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd
                http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
            <context:property-placeholder location="classpath:user.properties"/>
            <int:gateway id="gw" service-interface="org.springframework.integration.samples.ftp.ToFtpFlowGateway"
                default-request-channel="inbound"/>
            <bean id="ftpSessionFactory"
            class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
                <property name="host" value="${host}"/>
                <property name="port" value="${availableServerPort}"/>
                <property name="username" value="${userid}"/>
                <property name="password" value="${password}"/>
            </bean>
            <int-ftp:outbound-gateway id="gatewayGET"
                local-directory="#{ T(org.springframework.integration.samples.ftp.TestSuite).LOCAL_FTP_TEMP_DIR}/gatewayGET"
                session-factory="ftpSessionFactory"
                request-channel="inbound"       
                command="mget"
                command-options="-P"
                expression="'a.txt'"/>
        </beans>
    

    【讨论】:

    • 嗨,我注意到在您的回答中,您实际上并没有使用 Artem 提出的 &lt;request-handler-advice-chain&gt;。您是否还记得您是否遇到了问题,或者这仅仅是一个疏忽?我问的原因是因为我无法获得在 FTP 出站网关上使用 GET 命令启动的建议。虽然我使用的是 Java DSL,但这不应该有所作为。
    • 嗨 Hein,很遗憾我们决定不采用 SI 解决方案。即使在上面提到的所有配置之后,我们仍然遇到问题。切换到 apache FTP 客户端并在数小时内启动并运行。
    • 感谢您的回复。如果您或其他人仍然感兴趣,我发布了一个关于 RequestHandlerRetryAdvice/outbound-gateway here 的新问题。
    猜你喜欢
    • 2014-11-04
    • 2023-03-31
    • 2021-07-28
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-15
    相关资源
    最近更新 更多