1

Below is the sample code that I'm trying to test.

What is the default maxPoolSize for Jersey-2.33 (Reactive JAX-RS) Client and how to modify the same?

Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target(REST_URI);


    @GET
    @Path("/reactive")
    public void reactive( @Suspended final AsyncResponse asyncResponse) {
        
        CompletionStage<String> response = webTarget
                .request()
                .rx()
                .get(String.class);
        response.thenApply(res -> asyncResponse.resume(res)).exceptionally(e -> asyncResponse.resume(
                Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build()));


    }

The default ConnectionProvider is HttpUrlConnectorProvider, but I'm not able to figure out the default maxPoolSize or how to update the same.

I also tried to change the ConnectionProvider to ApacheConnectorProvider given below.

ClientConfig clientConfig = new ClientConfig();
       
        PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
        connectionManager.setMaxTotal(100);
        connectionManager.setDefaultMaxPerRoute(100);

        clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);

        ApacheConnectorProvider connector = new ApacheConnectorProvider();
        clientConfig.connectorProvider(connector);

        client = ClientBuilder.newClient(clientConfig);

But I kept on getting IllegalStateException error

"javax.ws.rs.ProcessingException: java.lang.IllegalStateException: Connection pool shut down"

I'm assuming as the call is non-blocking ( .rx() ), the ApacheConnectorProvider closes connection before getting response.

 CompletionStage<String> response = webTarget
                .request()
                .rx()
                .get(String.class);

In VertX the MaxPoolSize could be set by providing WebClientOptions

WebClientOptions webClientOptions = new WebClientOptions().setMaxPoolSize(maxPoolSize);
        this.client = WebClient.create(vertx,webClientOptions);

Is there a way to configure connection pool for Reactive Jersey (JAX-RS) Client ?

I also tried Jax rs client pool
and How does http connection pooling work in work in Jersey?

Hemanshu Belani
  • 199
  • 3
  • 13

0 Answers0