diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2021-05-26 15:06:21 +0200 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2021-05-26 15:06:21 +0200 |
commit | 1d9d274532ab3b0d5244039a28f5a999dc24d59e (patch) | |
tree | 249b0c84b12612efe4ddddf9946c73b4deb3dda2 /vespa-feed-client | |
parent | 6248f53f594530c5c272c5ca280573aef297522d (diff) |
Use H2AsyncClientBuilder for multiplexing
Diffstat (limited to 'vespa-feed-client')
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java | 62 |
1 files changed, 25 insertions, 37 deletions
diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java index 98edc32a107..49f79c07d37 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpFeedClient.java @@ -5,18 +5,14 @@ import org.apache.hc.client5.http.async.methods.SimpleHttpRequest; import org.apache.hc.client5.http.async.methods.SimpleHttpResponse; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; -import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder; -import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder; +import org.apache.hc.client5.http.impl.async.H2AsyncClientBuilder; import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder; import org.apache.hc.core5.concurrent.FutureCallback; import org.apache.hc.core5.http.ContentType; import org.apache.hc.core5.http.message.BasicHeader; -import org.apache.hc.core5.http2.HttpVersionPolicy; import org.apache.hc.core5.http2.config.H2Config; import org.apache.hc.core5.net.URIBuilder; -import org.apache.hc.core5.pool.PoolConcurrencyPolicy; import org.apache.hc.core5.reactor.IOReactorConfig; -import org.apache.hc.core5.util.TimeValue; import org.apache.hc.core5.util.Timeout; import javax.net.ssl.SSLContext; @@ -59,42 +55,34 @@ class HttpFeedClient implements FeedClient { } private static CloseableHttpAsyncClient createHttpClient(FeedClientBuilder builder, HttpRequestStrategy retryStrategy) throws IOException { - HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClientBuilder.create() - .setUserAgent(String.format("vespa-feed-client/%s", Vespa.VERSION)) - .setDefaultHeaders(Collections.singletonList(new BasicHeader("Vespa-Client-Version", Vespa.VERSION))) - .disableCookieManagement() - .disableRedirectHandling() - .disableConnectionState() - .setRetryStrategy(retryStrategy) - .setIOReactorConfig(IOReactorConfig.custom() - .setSoTimeout(Timeout.ofSeconds(10)) - .build()) - .setDefaultRequestConfig( - RequestConfig.custom() - .setConnectTimeout(Timeout.ofSeconds(10)) - .setConnectionRequestTimeout(Timeout.DISABLED) - .setResponseTimeout(Timeout.ofMinutes(5)) - .build()) - .setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_2) - .setH2Config(H2Config.initial() - .setMaxConcurrentStreams(builder.maxStreamsPerConnection) - .setCompressionEnabled(true) - .setPushEnabled(false) - .build()); - - PoolingAsyncClientConnectionManagerBuilder connectionManagerBuilder = PoolingAsyncClientConnectionManagerBuilder.create() - .setConnectionTimeToLive(TimeValue.ofMinutes(10)) - .setMaxConnTotal(builder.maxConnections) - .setMaxConnPerRoute(builder.maxConnections) - .setPoolConcurrencyPolicy(PoolConcurrencyPolicy.LAX); + H2AsyncClientBuilder httpClientBuilder = H2AsyncClientBuilder.create() + .setUserAgent(String.format("vespa-feed-client/%s", Vespa.VERSION)) + .setDefaultHeaders(Collections.singletonList(new BasicHeader("Vespa-Client-Version", Vespa.VERSION))) + .disableCookieManagement() + .disableRedirectHandling() + .setRetryStrategy(retryStrategy) + .setIOReactorConfig(IOReactorConfig.custom() + .setSoTimeout(Timeout.ofSeconds(10)) + .build()) + .setDefaultRequestConfig( + RequestConfig.custom() + .setConnectTimeout(Timeout.ofSeconds(10)) + .setConnectionRequestTimeout(Timeout.DISABLED) + .setResponseTimeout(Timeout.ofMinutes(5)) + .build()) + .setH2Config(H2Config.initial() + .setMaxConcurrentStreams(builder.maxStreamsPerConnection) + .setCompressionEnabled(true) + .setPushEnabled(false) + .build()); + ClientTlsStrategyBuilder tlsStrategyBuilder = ClientTlsStrategyBuilder.create() - .setSslContext(constructSslContext(builder)); + .setSslContext(constructSslContext(builder)); if (builder.hostnameVerifier != null) { tlsStrategyBuilder.setHostnameVerifier(builder.hostnameVerifier); } - connectionManagerBuilder.setTlsStrategy(tlsStrategyBuilder.build()); - httpClientBuilder.setConnectionManager(connectionManagerBuilder.build()); - return httpClientBuilder.build(); + return httpClientBuilder.setTlsStrategy(tlsStrategyBuilder.build()) + .build(); } private static SSLContext constructSslContext(FeedClientBuilder builder) throws IOException { |