使用不带轮询器的Spring Integration FTP客户端 [英] Use Spring Integration FTP client without the poller

查看:256
本文介绍了使用不带轮询器的Spring Integration FTP客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望有人可以帮助我...

Hoping somebody could help me with this one...

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

We have the following use case: upon request, connect to the remote FTP server, attempt up to 3 times to download the file (whose name and path is provided by the caller). Disconnect from the remote FTP server. Wait for next request.

由于Spring框架不提供FTP客户端解决方案,因此我们使用Spring Integration.我们遇到的问题是FTP inbound-channel-adapter需要设置轮询器,该轮询器会连续轮询远程服务器.在我们的情况下,我们最多只需要轮询3次,然后断开连接.然后等待下一个请求,依此类推.

Since the Spring framework doesn't provide FTP Client solution, we use Spring Integration for the purpose. The issue we ran into is that the FTP inbound-channel-adapter requires the poller to be set which continuously polls the remote server. In our case we only need to poll up to 3 times and then disconnect. Then wait for next request and so on.

Spring Integration有办法做到这一点吗?我们还有什么其他选择?

Is there a way to do this with Spring Integration? What other alternatives do we have?

推荐答案

感谢Artem为我指出正确的方向.发现此链接非常有用.

Thank you Artem for pointing me in the right direction. Found this link very helpful.

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

Here's the modified FtpOutboundGatewaySample-context.xml taken from that link that downloads the a.txt file from the FTP server. Notice that for performance reasons it doesn't execute LS and RM commands (only 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>

这篇关于使用不带轮询器的Spring Integration FTP客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆