java - 具有多个文件夹的 Sftp OutboundAdapter
问题描述
我需要将文件从本地传输到多个 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 文件夹?
解决方案
不,单个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")))
)
推荐阅读
- java - 无法使用 JFX 在 ubuntu 上运行 jar
- html - 如何在 Bootstrap 4 中端到端显示 3 个相等的列
- java - DataSeriesItem 可以分组而不是单独出现吗?
- google-apps-script - Google Apps 脚本 - 平面项目扣结构
- javascript - 按字符串数组对对象数组进行排序
- java - 数据范围提取问题的 Google Analytics API 限制
- java - 使用休眠的场景的实体类
- jquery - jquery 显示的表单输入未在提交时发布-codeigniter
- kubernetes - 非云环境下 kubernetes 的负载均衡
- visual-c++ - 无法使用 regsvr32 注册 NmsCmCommon.dll