[英]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.