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]

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

4

1 回答 1

0

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

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

于 2017-10-18T15:01:12.507 回答