在 Spring 集成中是否有可能保持 channel 同步(在发送消息后获得确认)但同时处理更多消息(并行处理)而不用线程创建自己的代码(即 ExecutorService 执行和提交工作程序)和等待他们?我想通过 FTP 使用但同时上传更多文件而不在代码中创建自己的线程来上传文件。我需要知道所有文件何时上传(这就是为什么我希望它是同步的)。是否可以通过 Spring 集成配置实现?如果可以,如何实现?
最佳答案
好吧,看起来你需要一些流程,比如:
<gateway>
将文件发送到 channel 并等待一些结果作为确认<splitter>
到ExecutorChannel
并行处理每个文件<int-ftp:outbound-gateway>
上传每个文件<aggregator>
关联和分组<int-ftp:outbound-gateway>
的结果<aggregator>
应该将其结果发送到<gateway>
,当时正在waitng。
如果有什么不清楚,请告诉我。
更新
How to do this in Spring Integration Java DSL any examples?
像这样:
@Configuration
@EnableIntegration
@IntegrationComponentScan
public class Configuration {
@Bean
public IntegrationFlow uploadFiles() {
return f ->
f.split()
.handle(Ftp.outboundGateway(this.ftpSessionFactory,
AbstractRemoteFileOutboundGateway.Command.PUT, "'remoteDirectory'"))
.aggregate();
}
}
@MessagingGateway(defaultRequestChannel = "uploadFiles.input")
interface FtpUploadGateway {
List<String> upload(List<File> filesToUpload);
}
关于java - spring integration中如何并行同步处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25741262/