【发布时间】:2020-09-11 15:29:24
【问题描述】:
假设我有ProductSupplier,它允许通过 id 获取产品。但它有限制,每个请求只能加载一种产品。
public interface ProductSupplier {
public Mono<Product> getById(Long productId);
}
现在我正在写 ProductService,我需要在其中按 id 获取产品列表
public interface ProductService {
ProductSupplier supplier;
public Mono<List<Product>> getByIds(Collection<Long> ids) {
return ids.stream()
.map(supplier::getById)//Stream<Mono<Product>>
//how to get Flux<Product> here?
.collectList();
}
}
【问题讨论】:
标签: java reactive spring-reactive spring-reactor