简体   繁体   English

如何使用 Spring Integration 在 IntegrationFlow 链中通过 SFTP 上传文件?

[英]How to upload file via SFTP inside an IntegrationFlow chain using Spring Integration?

What I'm trying to do is to check my local source directory for new file(s), do a simple transformation then send file(s) to a remote server via SFTP Using Spring Integration.我想要做的是检查我的本地源目录中的新文件,做一个简单的转换,然后使用 Spring Integration 通过 SFTP 将文件发送到远程服务器。

I'm using file adapter to poll my source directory for new files.我正在使用文件适配器轮询我的源目录中的新文件。 Now, I want to upload the file to remote server right after transforming it.现在,我想在转换文件后立即将文件上传到远程服务器。 Is there a message handler that do exactly that so I can trigger the upload inside my IntegrationFlow chain or should I write the file and SFTP upload it on a separate process (Create a scheduled job just for upload process)?是否有消息处理程序可以做到这一点,以便我可以在我的 IntegrationFlow 链中触发上传,还是应该编写文件并通过 SFTP 将其上传到单独的进程(仅为上传进程创建计划作业)?

    @Bean
    public IntegrationFlow integrationFlow() {
        return IntegrationFlows.from(fileReader(), spec -> spec.poller(Pollers.fixedDelay(1000)))
                .transform(transformer, "transform")
                .handle( message handler )
                .get();
    }

    @Bean
    public FileReadingMessageSource fileReader() {
        FileReadingMessageSource source = new FileReadingMessageSource();
        source.setDirectory(new File("src/main/resources/file/outbox"));
        return source;
    }

Updated Code:更新代码:

@Bean
    public IntegrationFlow integrationFlow() {
        return IntegrationFlows.from(fileReader(), spec -> spec.poller(Pollers.fixedDelay(1000)))
                .transform(transformer, "transform")
                .handle(Sftp.outboundAdapter(sftpSessionFactory)
                        .remoteDirectory(sftpRemoteDirectory)
                )
                .get();
    }

You are on the right track.你走在正确的轨道上。 There is indeed a channel adapter for SFTP to upload payload of the message as a file into a remote directory:确实有一个 SFTP 通道适配器可以将消息的有效负载作为文件上传到远程目录:

handle(Sftp.outboundAdapter(sessionFactory(), FileExistsMode.FAIL)

See more info in the SFTP chapter of the Spring Integration documentation:在 Spring Integration 文档的 SFTP 章节中查看更多信息:

https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#sftp-outbound https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#sftp-outbound

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Citrus Framework-使用Spring Integration通过SFTP上传文件 - Citrus Framework - upload file via SFTP using Spring Integration 我们如何在 Spring Boot 中模拟测试 IntegrationFlow。 我在使用 Spring Integration File 的 Spring Boot 应用程序中使用 Spring Integration - How can we mock test IntegrationFlow in spring boot. I am using Spring Integration inside a Spring boot app using Spring Integration File 无法使用 spring 集成将文件上传到 sftp 服务器 - Not able to upload file to sftp server using spring integration 如何配置 spring 集成适配器以通过 SFTP 获取和放置文件 - How to configure spring integration adapters to get and put a file via SFTP PipedOutput/InputStream 使用 spring 集成上传到 sftp - PipedOutput/InputStream upload to sftp using spring integration Spring 在 IntegrationFlow 中使用 DirectChannel 进行集成会引发“调度程序没有订阅者” - Spring Integration using DirectChannel in IntegrationFlow throws "Dispatcher has no subscribers" 如何使用 spring 与 sftp 集成上传和下载目录及其子目录 - How to upload and download a directory along with sub directory using spring integration with sftp 如何在不使用 spring 引导的情况下使用 spring 集成从 sftp 服务器下载文件 - how to download file from sftp server using spring integration without using spring boot Spring SFTP 集成未轮询文件 - Spring SFTP Integration is not polling the file 使用 spring 集成从 SFTP 服务器读取 excel 文件的问题 - Issue in reading a excel file from SFTP server using spring integration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM