Как настроить 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 не отправляется на move канал. Мне интересно, что мне не хватает.


person Ray Hunter    schedule 12.12.2018    source источник


Ответы (1)


Попробуйте вместо этого использовать 3 шлюза исходящей почты

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

В образце ftp показан похожий метод, но с RM, а не с MV (хотя он использует конфигурацию XML, потому что он довольно старый).

person Gary Russell    schedule 12.12.2018