2

我是 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>
4

1 回答 1

1

使用相同的共享metadataStore方法,但对于filter. 为此框架提供FtpPersistentAcceptOnceFileListFilterhttp ://docs.spring.io/spring-integration/reference/html/ftp.html#ftp-inbound

于 2016-04-28T18:58:38.917 回答