我有两个方法。
`Mono<Order> order = orderService.getById(UUID id);`
和
Mono<Truck> truck = vehicleService.getByTruckId(UUID truckId);
我从第一个请求中获得TruckId值。查看Order类
Order {
private UUID id;
private String name;
private UUID truckId;
}
如何将truckId
的值传递给vehicleService.getByTruckId(UUID truckId);
而不阻塞?
如果你只关心卡车
Mono<Truck> truckMono = order.flatMap(o -> getByTruckId(o.truckId));
如果你关心顺序的聚合,它是卡车
Mono<Order> orderMono = getById(UUID.randomUUID());
Mono<Truck> truckMono = orderMono.flatMap(o -> getByTruckId(o.truckId));
Mono<Result> resultMono = Mono.zip(orderMono, truckMono)
.flatMap(m -> Mono.just(new Result(m.getT1(), m.getT2())));
结果类
class Result {
public Result(Order order, Truck truck) {
this.order = order;
this.truck = truck;
}
Order order;
Truck truck;
}