【发布时间】:2018-12-09 15:48:53
【问题描述】:
我正在尝试使用新的 SpringBoot 2 Reactive WebClient 类(它没有批处理端点)对同一个休息服务进行并行(批处理)调用。例如,我需要 100 个“评论”对象(ID 为 1...100)并且我正在执行以下并行调用:
List<Mono<Comment>> monos = ids.stream()
.map(id -> webClient.get()
.uri("/comments/{id}", id)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(Comment.class))
.collect(Collectors.toList());
return Flux.merge(monos);
我是 Spring WebFlux 的新手,我不确定这是使用 WebClient 进行并行调用的正确方法
有没有更好(更合适)的方法来做到这一点(即做一个 Monos 的 Flux concat) ?
另外,当我这样做时,我使用了旧的已弃用的 AsyncRestTemplate
ThreadPoolExecutor...我应该使用类似的概念与
网络客户端? ... 是否有与响应式类似的东西?
问候
完整源码可以绑定在:https://github.com/fdlessard/SpringBootReactiveComment
【问题讨论】:
-
concat 将按顺序发送请求,而不是并行发送:projectreactor.io/docs/core/release/api/reactor/core/publisher/…。合并会这样做:projectreactor.io/docs/core/release/api/reactor/core/publisher/…
标签: spring-mvc spring-boot spring-webflux