我是Spring集成的新手,我尝试使用Spring集成FTP文件适配器从FTP位置读取文件来进行POC。 当我在两个Tomcat实例上部署我的应用程序时,我看到两个实例都从FTP位置下载文件。
我正在使用在我的机器上运行的虚拟FTP服务器(Xlight)。当我第一次将文件复制到远程目录时,两个实例都下载了文件,但是当我再将几个文件复制到远程文件夹时,其中一个实例都没有选择新添加的文件。 当我的应用程序部署在多个实例上时,我想要实现的一件事就是确保只处理一个文件。
请建议我缺少什么。
以下是我的配置文件:
<bean id="ftpSessionFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="${ftp.host}"/>
<property name="port" value="${ftp.port}"/>
<property name="username" value="${ftp.username}"/>
<property name="password" value="${ftp.password}"/>
<!-- whether server should connect to client's port or client should connect server port for initiating file transfer -->
<!-- <property name="clientMode" value="${ftp.clientMode}"/> -->
<!-- different file types involve ASCII , EBCDIC , BINARY (default) -->
<!-- <property name="fileType" value="${ftp.fileType}"/> -->
<!-- <property name="bufferSize" value="${ftp.bufferSize}"/> -->
</bean>
<int-ftp:inbound-channel-adapter id="ftpInbound" channel="ftpInboundChannel" session-factory="ftpSessionFactory" charset="UTF-8" auto-create-local-directory="true" delete-remote-files="false" remote-directory="/SpringFtpOutbound/remote" remote-file-separator="/" preserve-timestamp="false" temporary-file-suffix=".writing" local-filter="myFilter" local-directory="/work/SpringFtpInbound_2">
<int:poller fixed-rate="2000" max-messages-per-poll="1"/>
</int-ftp:inbound-channel-adapter>
<bean id="myFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
<list>
<bean class="org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFileListFilter">
<constructor-arg name="store" ref="metadataStore"/>
<constructor-arg value="*.*"/>
</bean>
<bean class="org.springframework.integration.file.filters.SimplePatternFileListFilter">
<constructor-arg value="*.xml" />
</bean>
</list>
</constructor-arg>
</bean>
<bean id="redisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:use-pool="true" p:host-name="localhost" p:port="6379" />
<bean name="metadataStore" class="org.springframework.integration.redis.metadata.RedisMetadataStore">
<constructor-arg name="connectionFactory" ref="redisConnectionFactory"/>
</bean>
<int-file:file-to-string-transformer id="myFileToStringTransfromer" input-channel="ftpInboundChannel" output-channel="transformChannel" />
<int-xml:xpath-splitter id="ftpFileSplitter" input-channel="transformChannel" output-channel="xpathSplitterChannel">
<int-xml:xpath-expression expression="/bancsRequest/input"/>
</int-xml:xpath-splitter>
<int:transformer id="myCustomTransformer" ref="myTransformerBean" input-channel="xpathSplitterChannel" method="transform" output-channel="ftpOutboundChannel">
</int:transformer>
<bean id="myTransformerBean" class="com.ntrs.geh.ftp.file.poc.transformer.MyXmlPayloadTransformer"/>
<int-jms:outbound-channel-adapter id="outboundChannelAdapter" channel="ftpOutboundChannel" jms-template="ftpOutQueueJmsTemplate" >
</int-jms:outbound-channel-adapter>
答案 0 :(得分:0)
使用相同的共享metadataStore
方法,但适用于filter
。
为此,Framework提供了FtpPersistentAcceptOnceFileListFilter
:http://docs.spring.io/spring-integration/reference/html/ftp.html#ftp-inbound