结合非阻塞和阻塞调用,并在Spring Webflux中返回结果。

问题描述 投票:0回答:0

我正在使用Spring Webflux和Spring boot 2,我的方案是这样的。

控制器

@GetMapping(path="/products")
public List<Products> getProducts(){
 return serviceObj.getProducts();
}

服务类

public List<Products> getProducts(){
List<Products> products = null;
  //Call 1 -> to repository class method returning Flux<Products>
repositoryObj.getProductsFlux();
  //Call 2 -> To repository class method returning List<Products>
repositoryObj.getProductsNormal();
  //Concat results from Call 1 & Call 2 and return List<Products>
return products;
}

如何在返回之前将Flux & normal产品列表中的结果连接起来呢?

P.S.我不想调用.block()和CompleteableFuture来处理从Call 1得到的结果。

spring-boot spring-webflux project-reactor nonblocking spring-reactive
© www.soinside.com 2019 - 2024. All rights reserved.