I am using Quarkus 2.10.2 and reactive rest clients. One of the rest clients (pas2clabService) is created using the RestClientBuilder and closed after the request in the IntegrationController has finished.
@RequestScoped
public class IntegrationController {
PAS2CLabService pas2clabService;
@PostConstruct
void postConstruct() {
this.pas2clabService = RestClientBuilder.newBuilder().baseUri(URI.create(integration.getUrl()))
.build(PAS2CLabService.class);
}
@PreDestroy
void preDestroy() {
this.pas2clabService.close();
}
public Uni<Optional<OverviewDocument>> getPAS2CLabOverview(String labCode) {
return pas2clabService.getWorklist()
.onItem().transform(response -> translatePAS2CLabWorklistResponse(response, labCode))
.onFailure().recoverWithItem(this::translatePAS2CLabWorklistResponse);
}
}
@RegisterRestClient(configKey = Integrations.PAS2CLAB_API)
@RegisterClientHeaders(PAS2CLabHeaderFactory.class)
@RegisterProvider(PASRestClientExceptionMapper.class)
public interface PAS2CLabService extends AutoCloseable {
@GET
@Path("/v1/worklist")
@Produces("application/json")
Uni<PAS2CLabWorklistResponse> getWorklist();
}
This approach has worked greatly with Quarkus 2.9.2 and older version, but since 2.10.2 the rest client is already closed when I invoke it via getPAS2CLabOverview. I can work around the problem by using @Singleton or @ApplicationScoped in the IntegrationController as this postpones the @PreDestroy event. I would however like to understand why I cannot use the @RequestScoped anymore and @PreDestroy is triggered before the Uni received an item.