0
votes

I want to load files via sftp from two separate directories into one local folder. So I have two inbound channel adapters like this:

<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>

And for example if a new file called "test.csv" become in the "remote-folder1" I have the following messages in the log:

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]

It looks weird and I don't know why I have two messages per one file. Maybe I have wrong configuration? Some could explain this behavior?

1

1 Answers

0
votes

Right, you are confused here because you have two polling channel adapters for the same local directory. So, One of the channel adapters downloads the file from SFTP and makes a message from its local copy. But at the same time we have second polling adapter for the same local dir. Right, this one does nothing for remote dir, but the local file is here and it is picked up the one more time.

You should consider to use different local directories or use local-filter do not "steal" files from another channel adapter.