gpt4 book ai didi

java - spring integration中如何并行同步处理?

转载 作者:搜寻专家 更新时间:2023-11-01 02:44:36 24 4
gpt4 key购买 nike

在 Spring 集成中是否有可能保持 channel 同步(在发送消息后获得确认)但同时处理更多消息(并行处理)而不用线程创建自己的代码(即 ExecutorService 执行和提交工作程序)和等待他们?我想通过 FTP 使用但同时上传更多文件而不在代码中创建自己的线程来上传文件。我需要知道所有文件何时上传(这就是为什么我希望它是同步的)。是否可以通过 Spring 集成配置实现?如果可以,如何实现?

最佳答案

好吧,看起来你需要一些流程,比如:

  1. <gateway>将文件发送到 channel 并等待一些结果作为确认

  2. <splitter>ExecutorChannel并行处理每个文件

  3. <int-ftp:outbound-gateway>上传每个文件

  4. <aggregator>关联和分组 <int-ftp:outbound-gateway> 的结果

  5. <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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com