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

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

问题描述:

我想通过sftp从两个单独的目录将文件加载到一个本地文件夹中。所以,我有两个入站通道适配器这样的: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”成为“远程文件夹1”我在日志中以下消息新的文件:

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] 

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

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

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

+0

感谢您的解释! 我一般想要的是通过sftp将文件递归复制(包括子目录)从远程服务器到本地目录。只需复制,无需进一步处理。 有没有任何解决方案来做到这一点与春季整合?我在文档中没有发现任何内容。你能劝我吗? –

+0

真的吗? 'MGET'如何:https://docs.spring.io/spring-integration/docs/4.3.12.RELEASE/reference/html/sftp.html#sftp-outbound-gateway? –