Quarkus RestClient close()

2.8k views Asked by At

I would like to know what is the behavior of quarkus when a RestClient is injected through CDI.

Does it close the client automatically in the example below?

@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@RegisterRestClient
@RegisterClientHeaders
public interface CarClient {
   @GET
   @Path("/cars/{id}")
   @Timeout(4500L)
   Car getCar(@PathParam("id") String id);
}

@Inject
@RestClient
CarClient carClient;

Or Quarkus requires it to extends AutoCloseable like the example below?

@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@RegisterRestClient
@RegisterClientHeaders
public interface CarClient extends AutoCloseable {
   @GET
   @Path("/cars/{id}")
   @Timeout(4500L)
   Car getCar(@PathParam("id") String id);
}

@Inject
@RestClient
CarClient carClient;

We are getting some warnings and we need to be sure if everything is being closed.

WARN: RESTEASY004687: Closing a class org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine instance for you. Please close clients yourself.

PS: Suggestion for the quarkus team to show in the warning the client with the issue :)

3

There are 3 answers

2
user4081947 On

Quarkus team said it was required to extends AutoCloseable in RestClient interfaces so connection is closed automatically.

0
WesternGun On

Actually this is bug. The workaround is to make the client extend Closeable(still present in Quarkus 2.16.1).