Theodosis
Theodosis

Reputation: 954

Quarkus Mutiny request ignored when using Unis.combinedWith

Hello i have the following problem. As you see i have created this 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);

Those three Unis make a request in 3 different microservices and I want to combine the response. I have used the following code in order to combine it


                    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 shows a warning saying that the combined will be ignored and it actually never runs. I have also tried using .await().indefinitely() but I receive the following error The current thread cannot be blocked: vert.x-eventloop-thread-11.

Upvotes: 0

Views: 847

Answers (1)

jponge
jponge

Reputation: 653

You need to subscribe or else no processing will ever be done (see https://smallrye.io/smallrye-mutiny/1.7.0/tutorials/hello-mutiny/#mutiny-uses-a-builder-api)

.await().indefinitely() is a blocking subscription where you block the current thread. Here you're blocking a Vert.x event-loop thread, hence you get a warning after some time.

This might also help: https://quarkus.io/guides/quarkus-reactive-architecture

Upvotes: 1

Related Questions