Java 具有多个文件夹的Sftp OutboundAdapter
我需要将文件从本地传输到多个sftp服务器文件夹。 这是我到目前为止的代码,我正在使用单通道进行一对一传输:Java 具有多个文件夹的Sftp OutboundAdapter,java,spring-integration,sftp,spring-integration-sftp,Java,Spring Integration,Sftp,Spring Integration Sftp,我需要将文件从本地传输到多个sftp服务器文件夹。 这是我到目前为止的代码,我正在使用单通道进行一对一传输: private IntegrationFlow localToRemotePush(final String localDirectory,String remoteDirectory, String adapterName) { return IntegrationFlows .from(Files.inboundAdapter(Paths.ge
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()
是不可能的。它只针对单个远程目录设计,但是,可以通过函数或表达式从请求消息中确定该目录。但这是不同的故事
对于每个远程目录和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")))
)
感谢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()
:您可以使用fileNameGenerator()
取而代之的是为其lambda提供更好的内容助手