I found solution on Quarkus issues page (https://github.com/quarkusio/quarkus/issues/28808) and commit solution to existing project(https://github.com/Lukec1/quarkus-3.0.0.CR2-sample/commit/98a4791571334a898716d7780a87d993d443f5c6).
Edited: recognized problem is when using Panache Hibernate Reactive and Uni.combine
. Because of that i now use chain approach which does not work in parallel as we would like with the Uni.combine
.
ZooService
public Uni<List<Dog>> getDogs(String owner) {
return zooRepository.getDogs(owner);
}
public Uni<List<Cat>> getCats(String owner) {
return zooRepository.getCats(owner);
}
public Uni<List<Rat>> getRats(String owner) {
return zooRepository.getRats(owner);
}
public Uni<List<Dolphin>> getDoplphins(String owner) {
return zooRepository.getDoplphins(owner);
}
ZooRepository
private Uni<List<AnimalEntity>> getAnimals(String ownerId, AnimalType animalType) {
return list("ownerId = ?1 AND animalType = ?2", ownerId, animalType).log()
.onItem()
.invoke(
result ->
log.debug(
"Found {} entities for parameters '{}' - '{}'",
result.size(),
ownerId,
animalType))
.onFailure()
.invoke(
throwable ->
log.error(
"Error while getting accounts for parameters '{}' - '{}'",
ownerId,
animalType,
throwable));
}
@WithSession
public Uni<List<Dog>> getDogs(String ownerId) {
return getAnimals(ownerId, AnimalType.DOG).map(animalEntityMapper::mapToDogs);
}
@WithSession
public Uni<List<Cat>> getCats(String ownerId) {
return getAnimals(ownerId, AnimalType.CAT).map(animalEntityMapper::mapToCats);
}
@WithSession
public Uni<List<Rat>> getRats(String ownerId) {
return getAnimals(ownerId, AnimalType.RAT).map(animalEntityMapper::mapToRats);
}
@WithSession
public Uni<List<Dolphin>> getDoplphins(String ownerId) {
return getAnimals(ownerId, AnimalType.DOLPHIN).map(animalEntityMapper::mapToDolphins);
}
Code which need to work, but not:
Uni<List<Dog>> dogs = zooService.getDogs(owner);
Uni<List<Cat>> cats = zooService.getCats(owner);
Uni<List<Rat>> rats = zooService.getRats(owner);
Uni<List<Dolphin>> dolphins = zooService.getDoplphins(owner);
final AnimalsDto summary = new AnimalsDto();
return Uni.combine().all().unis(dogs, cats, rats,
dolphins).asTuple().map(animal -> {
summary.setDogs(animal.getItem1());
summary.setCats(animal.getItem2());
summary.setRats(animal.getItem3());
summary.setDolphins(animal.getItem4());
return summary;
});
and implemented working solution founded from Quarkus github issues:
return dogs.invoke(summary::setDogs)
.chain(() -> cats.invoke(summary::setCats))
.chain(() -> rats.invoke(summary::setRats))
.chain(() -> dolphins.invoke(summary::setDolphins))
.replaceWith(summary);