你好我有以下問題。如您所見,我創建了這 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);
這三個 Uni 在 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。
uj5u.com熱心網友回復:
您需要訂閱,否則將不會進行任何處理(請參閱https://smallrye.io/smallrye-mutiny/1.7.0/tutorials/hello-mutiny/#mutiny-uses-a-builder-api)
.await().indefinitely()是一個阻塞訂閱,您可以在其中阻塞當前執行緒。在這里,您阻塞了 Vert.x 事件回圈執行緒,因此您會在一段時間后收到警告。
這也可能有幫助:https ://quarkus.io/guides/quarkus-reactive-architecture
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/527493.html
標籤:爪哇夸库斯兵变
