我有兩種方法。
`Mono<Order> order = orderService.getById(UUID id);`
和
Mono<Truck> truck = vehicleService.getByTruckId(UUID truckId);
我從第一個請求中獲取了 TruckId 值。查看訂單類
Order {
private UUID id;
private String name;
private UUID truckId;
}
如何在不阻塞的情況下將此truckId值傳遞給?vehicleService.getByTruckId(UUID truckId);
uj5u.com熱心網友回復:
如果你只關心卡車
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;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/534310.html
