使用Unis.combinedWith时忽略Quarkus Mutiny请求



你好,我有以下问题。正如你所看到的,我已经创建了这个3 Unis

Uni<List<JsonObjectCar>> carDoorsUni = getDoors(variable1,
variable2, variable3);
Uni<List<JsonObjectCar>> carWheelsUni = getWheels(variable1,
variable2, variable3);
Uni<List<JsonObjectCar>> carWindowsUni = getWindows(variable1,
variable2, variable3);

这三个Unis在3个不同的微服务中提出了请求,我想将响应组合起来。我使用了以下代码来组合它


Uni.combine()
.all()
.unis(carDoorsUni, carWheelsUni, carWindowsUni)
.combinedWith((carDoors, carWheels, carWindows) -> {
Optional.of(carDoors)
.ifPresent(val -> car.setDoors(val.getDoors()));
Optional.of(carWheels)
.ifPresent(val -> car.setWheels(val.getWheels()));
Optional.of(carWindows)
.ifPresent(val -> car.setWindows(val.getWindows()));
return car;
});

Intellij显示一个警告,表示组合将被忽略,并且它实际上永远不会运行。我也尝试过使用.await().indefinitely(),但收到以下错误The current thread cannot be blocked: vert.x-eventloop-thread-11

您需要订阅,否则将不会进行任何处理(请参阅https://smallrye.io/smallrye-mutiny/1.7.0/tutorials/hello-mutiny/#mutiny-使用构建者api(

.await().indefinitely()是一个阻塞订阅,您可以在其中阻塞当前线程。在这里,您阻塞了Vert.x事件循环线程,因此在一段时间后会收到警告。

这也可能有助于:https://quarkus.io/guides/quarkus-reactive-architecture

最新更新