问题
Hoping somebody could help me with this one...
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.
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.
Is there a way to do this with Spring Integration? What other alternatives do we have?
回答1:
The Spring Integration FTP module provides the <int-ftp:outbound-gateway>
with GET
command for your case. Plus there is a retry
support out-of-the-box in face of <request-handler-advice-chain>
and RequestHandlerRetryAdvice
.
Please, refer to Spring Integration Reference Manual for more information.
回答2:
Thank you Artem for pointing me in the right direction. Found this link very helpful.
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>
来源:https://stackoverflow.com/questions/31254222/use-spring-integration-ftp-client-without-the-poller