java - 具有多个文件夹的 Sftp OutboundAdapter

标签 java spring-integration sftp spring-integration-sftp

我需要将文件从本地传输到多个 sftp 服务器文件夹。 到目前为止,这是我的代码,我正在使用单 channel 进行一对一传输:

private IntegrationFlow localToRemotePush(final String localDirectory,String remoteDirectory, String adapterName) {    
    return IntegrationFlows
            .from(Files.inboundAdapter(Paths.get(localDirectory).toFile())
                                .regexFilter(FILE_PATTERN_REGEX)
                                .preventDuplicates(false),
                        e -> {
                            e.poller(Pollers.fixedDelay(getPollerIntervalMs())
                                    .maxMessagesPerPoll(getMaxFetchSize())
                                    .errorChannel("errorChannel")
                                    .transactional(transactionManager)
                                    .transactionSynchronizationFactory(mmPushSftpSyncFactory()) // moves processed files
                            ).id(adapterName);
                        })
            .handle(Sftp.outboundAdapter(mmPushSftpSessionFactory())
                        .remoteDirectory(getRemoteRootDir() + remoteDirectory1)
                        //.remoteDirectory(getRemoteRootDir() + remoteDirectory2) --- this way is correct ?
                        .temporaryFileSuffix(".tmp"))
            .get();
}

是否可以使用单 channel 将本地文件从一个本地文件夹传输到多个 sftp 文件夹?

最佳答案

不,使用单个 Sftp.outboundAdapter() 是不可能的。它仅设计用于单个远程目录,但是可以通过函数或表达式从请求消息中确定该目录。但那是另外一回事了。

您的任务可以通过针对每个远程目录和publishSubscribe 配置的多个Sftp.outboundAdapter() 来实现。像这样:

.publishSubscribeChannel(s -> s
                        .subscribe(f -> f
                                .handle(Sftp.outboundAdapter(mmPushSftpSessionFactory())
                                          .remoteDirectory(getRemoteRootDir() + remoteDirectory1)
                                          .temporaryFileSuffix(".tmp")))
                        .subscribe(f -> f
                                .handle(Sftp.outboundAdapter(mmPushSftpSessionFactory())
                                          .remoteDirectory(getRemoteRootDir() + remoteDirectory2)
                                          .temporaryFileSuffix(".tmp")))
                )

关于java - 具有多个文件夹的 Sftp OutboundAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54204455/

相关文章:

c# - 使用 WinSCP .NET 程序集列出具有特定扩展名的文件

java - 安全非重复随机字母数字 URL slug

java - USB-RS232通讯

java - 如何设置 Spring TCP 客户端和服务器模型?

java - Spring Integration 一直消耗更多内存

c - SFTP libssh 失败

java - 使用 jsch 将远程服务器中的目录移动到同一远程服务器中的另一个位置

java - 使用 Postgresql 的 Spring Boot 的 Tomcat 配置

java - 在 Java 中以 Base64 编码来自 URL 的图像

java - 如何使用 Spring Integration 从 Java bean 正确创建 RabbitMQ 自定义消息?