我尝试使用Tuple3
将3个Flux
对象聚合为1个对象。但是,我仍然卡住了。我在网上搜索,看到可以使用Mono.zip()
,但不适用于Flux
。
public class OrderService {
private final AppWebClient appWebClient;
public Mono<OrderDetailsAggregate> getAggregatedOrderDetails(List<String> orderNoList1,
List<String> orderNoList2, List<String> orderNoList3) {
Flux<Map<String, List<String>>> fluxOne = this.appWebClient.getFluxOne(orderNoList1);
Flux<Map<String, String>> fluxTwo = this.appWebClient.getFluxTwo(orderNoList2);
Flux<Map<String, List<String>>> fluxThree = this.appWebClient.getFluxThree(orderNoList3);
return Mono.zip(fluxOne, fluxTwo, fluxThree).map(this::combine); //error here
}
private OrderDetailsAggregate combine(
Tuple3< Flux<Map<String, List<String>>>, Flux<Map<String, String>>, Flux<Map<String, List<String>>> > tuple) {
return OrderDetailsAggregate.create(tuple.getT1(), tuple.getT2(), tuple.getT3());
}
}
fluxOne
、fluxTwo
和fluxThree
具有不同的数据类型。
订单详细信息聚集类
@Data
@ToString
@AllArgsConstructor(staticName = "create")
public class OrderDetailsAggregate {
private Flux<Map<String, List<String>>> fluxOne;
private Flux<Map<String, String>> fluxTwo;
private Flux<Map<String, List<String>>> fluxThree;
}
我如何将它们结合起来?
谢谢你。
1条答案
按热度按时间dgtucam11#
如果你需要从
getAggregatedOrderDetails
方法返回Mono<OrderDetailsAggregate>
,那么为什么不创建一个没有zip的Mono
对象呢?