Setting maximum http connections for Apache fluent executor

1.9k views Asked by At

Apache fluent API allows simple one-line http calls like:

String content = Request.Get(url).execute().returnContent().asString();

Which is executed by a ...fluent.Executor, whose javadoc says:

A PoolingHttpClientConnectionManager with maximum 100 connections per route and a total maximum of 200 connections is used internally

I would like to change the maximum connection parameters to be used for a specific call, but I can't find a way to access the connection manager used by the above code. I have tried:

Executor.newInstance().execute(Request.Get("")).returnContent().asString();

but there is no way to change these parameters on the Executor returned by Executor.newInstance().

Is there is way to use the fluent API but with custom maximum connection values?

1

There are 1 answers

0
ok2c On BEST ANSWER

One can bind an instance of the fluent executor to an arbitrary HttpClient instance

PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
CloseableHttpClient client = HttpClients.custom()
        .setConnectionManager(cm)
        .build();
cm.setDefaultMaxPerRoute(15);
Executor.newInstance(client).execute(Request.Get("/")).discardContent();