【问题标题】:Sftp OutboundAdapter with multiple folders具有多个文件夹的 Sftp OutboundAdapter
【发布时间】:2019-01-15 17:58:56
【问题描述】:

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

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();
}

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

【问题讨论】:

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


    【解决方案1】:

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

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

    .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")))
                    )
    

    【讨论】:

    • 感谢 Artem,是否可以将文件名从本地更改为远程?试过 SFTP.Outbound this .fileNameExpression("payload.getName().replaces('HIGH_VAL',VAL')") 我试过这样但我收到这个错误 EL1004E: Method call: Method replaces(java.lang.String, java.lang.String) 在 java.lang.String 类型上找不到
    • 因为方法名是replace()docs.oracle.com/javase/7/docs/api/java/lang/…
    • 您可以使用fileNameGenerator() 来为其 lambda 提供更好的内容助手
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 2014-08-09
    • 2015-11-27
    • 2021-12-23
    相关资源
    最近更新 更多