I have an application that uses spring integration to poll files from the SFTP and process them. The structure of the sftp will be always similar, but new folders are going to be created. Example:
/sales/client1/in
/sales/client2/in
...
/sales/clientN/in
I'm using a Sftp Inbound Adapter to poll the SFTP server and start the flow, something like:
@Bean
public IntegrationFlow flow() {
return IntegrationFlows.from(
Sftp.inboundAdapter(sftpSessionFactory())
.preserveTimestamp(true)
.localDirectory(new File("sftp-inbound"))
.deleteRemoteFiles(true)
.autoCreateLocalDirectory(true)
.remoteDirectoryExpression(
EXPRESSION_PARSER.parseExpression("@directoryProvider.getDirectory()"))
.filter(getFilter())
, e -> e.id("sftpInboundAdapter")
.autoStartup(true)
.poller(Pollers.fixedDelay(5, TimeUnit.SECONDS)))
.log()
.channel("processing")
.get();
}
The bean directoryProvider
will get the folders from the DB and will go in round-robin returning each folder, which according to what I understood from the documentation:
Starting with version 4.2, you can specify remote-directory-expression instead of remote-directory, letting you dynamically determine the directory on each poll — for example, remote-directory-expression="@myBean.determineRemoteDir()"
it's what I'm needing, however, the method getDirectory
is only executed twice when the IntegrationFlow is created and instead of getting a new folder on each poll, it uses the second one that was retrieved and is not asking again.
Did I understood wrong the documentation? Is there an easy way to do this, like a wild card for the intermediate folder structure? sales/*/in
? Thanks!
See Inbound Channel Adapters: Polling Multiple Servers and Directories.
Use a RotatingServerAdvice
with a custom RotationPolicy
.
Or use an outbound gateway instead, with a recursive MGET command.