如何通过 ftp 入站通道适配器轮询本地 ftp 目录?

how to poll local ftp directory through ftp inbound channel adaptor?

我是 spring integration.So 的新手,如果我问的是普通问题,请原谅我。我确实有一个简单的用例。我已经配置 ftp 入站通道适配器如下。使用它我可以在本地目录中提取远程检查文件。 i.e.D:/出站。现在我想轮询本地目录,即 i.e.D:/Outbound 以添加更多业务逻辑。即根据检查文件状态从远程下载原始文件并将相关检查文件移动到其他目录位置。我应该怎么做?任何示例快速代码或参考 guide/links 将不胜感激。

    <?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:int="http://www.springframework.org/schema/integration"
       xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd">

  <context:property-placeholder location="/ftp/ftp.properties"/>
  <context:component-scan base-package="com.sandbox.ftp"/>

  <!-- FTP inbound channel adapter for reading the input check files -->
  <int-ftp:inbound-channel-adapter id="ftpInbound"
                                   channel="ftpInboudChannel"
                                   session-factory="ftpClientFactory"
                                   auto-create-local-directory="true"
                                   local-directory="D:/outBound"
                                   remote-directory="."
                                   filename-regex=".*\.chk$">
            <int:poller fixed-rate="5000" />
  </int-ftp:inbound-channel-adapter>

  <int:channel id="ftpInboudChannel"/>

  <!--Service Activator which will intiates the download of original source file  -->
  <int:service-activator input-channel="ftpInboudChannel" ref="myPojo" method="processFile" />
  <bean id="myPojo" class="com.sandbox.ftp.CheckFileProcessor" />

  <!-- FTP inbound channel adapter for downloading the original remote files -->
  <int-ftp:inbound-channel-adapter id="ftpInboundDownload"
                                   channel="ftpInboudDownloadChannel"
                                   session-factory="ftpClientFactory"
                                   auto-create-local-directory="true"
                                   local-directory="D:/outBound/original"
                                   remote-directory="."
                                   filename-regex=".*\.txt$">
            <int:poller fixed-rate="5000"/>
  </int-ftp:inbound-channel-adapter>

  <int:channel id="ftpInboudDownloadChannel"/>


</beans>

现在根据 Gary 的评论,我已经使用了服务激活器并能够下载原始源 files.i.e。 *。文本文件。现在我想在下载原始源文件后将关联的检查文件移动到同一文件夹。即 *.chk 到 D:/outBound/original。有什么想法吗?

所做的只是将文件转储到队列通道中 - 我假设您是从示例应用程序中获得的。

参见spring integration reference

一个简单的应用程序可能会执行此操作(从频道中删除 <queue/>)...

<int:channel id="ftpInboudChannel"/>

<int:service-activator input-channel="ftpInboudChannel"
    ref="myPojo" method="processFile" />

<bean id="myPojo" class="foo.MyPojo" />

public class MyPojo {

    public void processFile(File fileToProcess) {
        ...
    }
}

编辑

我不完全确定你的用例是什么,但听起来你只想在 .chk 文件存在时获取 .txt 文件。

入站通道适配器不太适合 - 它所做的只是将本地目录同步到远程目录,听起来您需要这样的东西,将 GET 命令与出站通道适配器一起使用...

<int:channel id="ftpInboudChannel"/>

<int:transformer input-channel="ftpInboudChannel" output-channel="ftpGet"
    expression="payload.name.replace('chk$', 'txt')" />

<int:ftp-outbound-gateway request-channel="ftpGet" command="get"
     ...
    replyChannel="ftpGot" />

<int:service-activator input-channel="ftpGot" ... />

换句话说,按需获取文件而不是轮询。

您还可以使用网关列出 (LS) 文件并获取您感兴趣的文件。