我有以下与远程服务器同步sftp文件的kotlin配置。
@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通道。我想知道我错过了什么。
发布于 2018-12-12 22:41:23
考虑使用3个出站网关
...LSgateway->splitter->GETgateway->process->MVgatewayftp sample展示了类似技术,但使用的是RM而不是MV (尽管is使用XML配置,因为它非常旧)。
https://stackoverflow.com/questions/53735484
复制相似问题