【问题标题】:Sftp inbound channel adapter: duplicate messagesSftp 入站通道适配器:重复消息
【发布时间】:2017-10-18 14:21:42
【问题描述】:

我想通过 sftp 将文件从两个单独的目录加载到一个本地文件夹中。所以我有两个像这样的入站通道适配器:

<bean id="lastModifiedFileFilter" class="com.test.sftp.SftpLastModifiedFileListFilter">
    <constructor-arg name="age" value="100"/>
</bean>

<int:poller id="fixedRatePoller" fixed-rate="100"
            time-unit="SECONDS"/>

<int-sftp:inbound-channel-adapter id="inbound1"
                                  session-factory="sftpSessionFactory"
                                  auto-create-local-directory="true"
                                  delete-remote-files="true"
                                  remote-directory="/remote-folder1"
                                  filter="lastModifiedFileFilter"
                                  local-directory="/local-folder"
                                  channel="nullChannel">
   <int:poller ref="fixedRatePoller"/>
</int-sftp:inbound-channel-adapter>

<int-sftp:inbound-channel-adapter id="inbound2"
                                  session-factory="sftpSessionFactory"
                                  auto-create-local-directory="true"
                                  delete-remote-files="true"
                                  remote-directory="/remote-folder2"
                                  filter="lastModifiedFileFilter"
                                  local-directory="/local-folder"
                                  channel="nullChannel">
   <int:poller ref="fixedRatePoller"/>
</int-sftp:inbound-channel-adapter>

例如,如果一个名为“test.csv”的新文件位于“remote-folder1”中,我会在日志中显示以下消息:

INFO  Created message: [GenericMessage [payload=local-folder/test.csv, headers={id=bb76252a-e826-579d-b0e1-cab55a7cc957, timestamp=1508242673896}]] [task-scheduler-6][FileReadingMessageSource]
INFO  Created message: [GenericMessage [payload=local-folder/test.csv, headers={id=a76de653-f805-8add-1e02-924d0915a18c, timestamp=1508242673962}]] [task-scheduler-2][FileReadingMessageSource]

看起来很奇怪,我不知道为什么每个文件有两条消息。也许我有错误的配置?有人可以解释这种行为吗?

【问题讨论】:

    标签: spring-integration spring-integration-sftp


    【解决方案1】:

    是的,您在这里感到困惑,因为您有两个用于同一个本地目录的轮询通道适配器。因此,其中一个通道适配器从 SFTP 下载文件并从其本地副本发出消息。但同时我们有第二个轮询适配器用于相同的本地目录。对,这个对远程目录没有任何作用,但是本地文件在这里,它被再次拾取。

    您应该考虑使用不同的本地目录或使用local-filter 不要从另一个通道适配器“窃取”文件。

    【讨论】:

    • 感谢您的解释!我一般想要的是通过 sftp 从远程服务器递归地复制文件(包括子目录)到本地目录。只需复制,无需任何进一步处理。有什么解决方案可以通过 spring 集成来做到这一点吗?我在文档中一无所获。你能给我建议吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多