如何配置spring-integration sftp,以便在远程文件下载到本地文件系统后将其移动



我有下面的kotlin配置,用于与远程服务器同步sftp文件。

@Bean
fun sessionFactory(): SessionFactory<ChannelSftp.LsEntry> {
val factory = DefaultSftpSessionFactory(true)
factory.setHost(sftpHost)
factory.setPort(sftpPort.toInt())
factory.setUser(sftpUser)
factory.setPassword(sftpPasword)
factory.setAllowUnknownKeys(true)
return CachingSessionFactory<ChannelSftp.LsEntry>(factory)
}
@Bean
fun template(): SftpRemoteFileTemplate {
return SftpRemoteFileTemplate(sessionFactory())
}
@Bean
fun sftpInboundFileSynchronizer(): SftpInboundFileSynchronizer {
val fileSynchronizer = SftpInboundFileSynchronizer(sessionFactory())
fileSynchronizer.setDeleteRemoteFiles(false)
fileSynchronizer.setRemoteDirectory(sftpRemoteDirectoryDownload)
fileSynchronizer.setFilter(SftpPersistentAcceptOnceFileListFilter(PropertiesPersistingMetadataStore(), "downloaded"))
return fileSynchronizer
}
@Bean
@InboundChannelAdapter(channel = "download", poller = [Poller(cron = "0/5 * * * * *")])
fun sftpMessageSource(): MessageSource<File> {
val source = SftpInboundFileSynchronizingMessageSource(sftpInboundFileSynchronizer())
source.setLocalDirectory(File(sftpLocalDirectoryDownload))
source.setAutoCreateLocalDirectory(true)
source.setLocalFilter(FileSystemPersistentAcceptOnceFileListFilter(PropertiesPersistingMetadataStore(), "downloaded"))
return source
}
@Bean
@ServiceActivator(inputChannel = "download", outputChannel = "move")
fun resultFileHandler(): MessageHandler {
return MessageHandler { message -> publisher.handleMessage(message) }
}
@Bean
@ServiceActivator(inputChannel = "move")
fun sftpOutboundGateway(sessionFactory: SessionFactory<ChannelSftp.LsEntry>): SftpOutboundGateway {
val gateway = SftpOutboundGateway(sessionFactory, "mv", "payload")
gateway.setOutputChannelName("errorChannel")
return gateway
}

我想做的是在文件从远程服务器下载后移动它;然而,我还没有找到一种行之有效的方法。大多数示例都使用xml配置。

一切都在进行resultFileHandler方法调用,在那里我可以处理本地文件;然而,MessageHandler没有被发送到CCD_ 2信道。我想知道我错过了什么。

考虑使用3个出站网关代替

...LSgateway->splitter->GETgateway->process->MVgateway

ftp示例显示了类似的技术,但使用RM而不是MV(尽管它使用XML配置,因为它很旧(。

最新更新