2017-10-18 15 views
0

두 개의 개별 디렉토리에서 하나의 로컬 폴더로 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> 

그리고 예를 들어

경우 "원격 폴더 1"나는 로그에 다음과 같은 메시지가에가 "test.csv"라는 새로운 파일을

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] 

이상하게 보입니다. 이유는 하나의 파일 당 두 개의 메시지가 있습니다. 어쩌면 내가 잘못된 구성을 가지고 있을까요? 어떤 사람들은이 행동을 설명 할 수 있습니까?

답변

0

동일한 로컬 디렉토리에 대해 폴링 채널 어댑터가 두 개 있기 때문에 여기서는 혼란 스럽습니다. 따라서 채널 어댑터 중 하나가 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? –