首页 文章

Sftp入站通道适配器:重复的消息

提问于
浏览
0

我想通过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]

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

1 回答

  • 0

    对,你在这里很困惑,因为你有两个同一本地目录的轮询通道适配器 . 因此,其中一个通道适配器从SFTP下载文件并从其本地副本发出消息 . 但同时我们为同一个本地目录安装了第二个轮询适配器 . 是的,这个没有为远程目录做任何事情,但本地文件在这里,它再次被接收 .

    您应该考虑使用不同的本地目录或使用另一个通道适配器的 local-filter 不"steal"文件 .

相关问题