【问题标题】:How to configure spring-integration-sftp to move a remote file after it has been downloaded to local filesystem?将远程文件下载到本地文件系统后,如何配置 spring-integration-sftp 以移动远程文件?
【发布时间】: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


    【解决方案1】:

    考虑改为使用 3 个出站网关

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

    ftp sample 显示了类似的技术,但使用的是 RM 而不是 MV(虽然它使用 XML 配置,因为它已经很老了)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      • 2022-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多