From 35d1a3ae311da1245b02b68582f77991d4b2745d Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Mon, 16 Jan 2023 14:40:34 -0500 Subject: [PATCH 1/2] Document HTTP/2 support Signed-off-by: Andriy Redko --- CHANGELOG.md | 1 + USER_GUIDE.md | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0456681d7..6da8de47ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Add 1-click release workflows ([#321](https://github.com/opensearch-project/opensearch-java/pull/321)) - Introduce new OpenSearchTransport based on Apache HttpClient 5 ([#281](https://github.com/opensearch-project/opensearch-java/pull/281)) - Add workflow to publish snapshots via GHA ([#325](https://github.com/opensearch-project/opensearch-java/pull/325)) +- Document HTTP/2 support ([#330](https://github.com/opensearch-project/opensearch-java/pull/330)) ### Dependencies - Bumps `classgraph` from 4.8.149 to 4.8.154 diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 569274ec46..2958e2f22f 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -68,6 +68,8 @@ Transport transport = new RestClientTransport(restClient, OpenSearchClient client = new OpenSearchClient(transport); ``` +Upcoming OpenSearch `3.0.0` release brings HTTP/2 support and as such, the `RestClientTransport` would switch to HTTP/2 if available (for both HTTPS and/or HTTP protocols). The desired protocol could be forced using `RestClientBuilder.HttpClientConfigCallback`. + ### Create a client using `ApacheHttpClient5Transport` ```java @@ -78,6 +80,8 @@ final Transport transport = ApacheHttpClient5TransportBuilder OpenSearchClient client = new OpenSearchClient(transport); ``` +Upcoming OpenSearch `3.0.0` release brings HTTP/2 support and as such, the `ApacheHttpClient5Transport` would switch to HTTP/2 if available (for both HTTPS and/or HTTP protocols). The desired protocol could be forced using `ApacheHttpClient5TransportBuilder.HttpClientConfigCallback`. + ## Create an index ```java From b51e40e375383e981587948147adfea3019f26e3 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Tue, 17 Jan 2023 12:48:37 -0500 Subject: [PATCH 2/2] Addressing code review comments Signed-off-by: Andriy Redko --- USER_GUIDE.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 2958e2f22f..63f548e3da 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -56,14 +56,14 @@ There are multiple low level transports which `OpenSearchClient` could be config ### Create a client using `RestClientTransport` ```java -Transport transport = new RestClientTransport(restClient, new JacksonJsonpMapper()); +OpenSearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper()); OpenSearchClient client = new OpenSearchClient(transport); ``` The `JacksonJsonpMapper` class (2.x versions) only supports Java 7 objects by default. [Java 8 modules](https://github.com/FasterXML/jackson-modules-java8) to support JDK8 classes such as the Date and Time API (JSR-310), `Optional`, and more can be used by including [the additional datatype dependency](https://github.com/FasterXML/jackson-modules-java8#usage) and adding the module. For example, to include JSR-310 classes: ```java -Transport transport = new RestClientTransport(restClient, +OpenSearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper(new ObjectMapper().registerModule(new JavaTimeModule()))); OpenSearchClient client = new OpenSearchClient(transport); ``` @@ -73,14 +73,28 @@ Upcoming OpenSearch `3.0.0` release brings HTTP/2 support and as such, the `Rest ### Create a client using `ApacheHttpClient5Transport` ```java -final Transport transport = ApacheHttpClient5TransportBuilder +final OpenSearchTransport transport = ApacheHttpClient5TransportBuilder .builder(hosts) .mapper(new JacksonJsonpMapper()) .build(); OpenSearchClient client = new OpenSearchClient(transport); ``` -Upcoming OpenSearch `3.0.0` release brings HTTP/2 support and as such, the `ApacheHttpClient5Transport` would switch to HTTP/2 if available (for both HTTPS and/or HTTP protocols). The desired protocol could be forced using `ApacheHttpClient5TransportBuilder.HttpClientConfigCallback`. +Upcoming OpenSearch `3.0.0` release brings HTTP/2 support and as such, the `ApacheHttpClient5Transport` would switch to HTTP/2 if available (for both HTTPS and/or HTTP protocols). The desired protocol could be forced using `ApacheHttpClient5TransportBuilder.HttpClientConfigCallback`, for example: + +```java +final OpenSearchTransport transport = ApacheHttpClient5TransportBuilder + .builder(httpHost) + .setMapper(new JacksonJsonpMapper()) + .setHttpClientConfigCallback(new ApacheHttpClient5TransportBuilder.HttpClientConfigCallback() { + @Override + public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) { + return httpClientBuilder.setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_2); + } + }) + .build(); +OpenSearchClient client = new OpenSearchClient(transport); +``` ## Create an index