【发布时间】:2018-12-12 03:08:57
【问题描述】:
我有以下 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 没有被发送到 move 频道。我想知道我错过了什么。
【问题讨论】:
标签: java spring spring-integration spring-integration-sftp