Skip to content

Commit 90292f2

Browse files
authored
[DOCS] Add transport.close() to connecting page (#807)
* [DOCS] Add transport.close() to connecting page Without this line, the code hangs because the HttpClient thread keeps running indefinitely. * Replace tabs with spaces
1 parent 64ec619 commit 90292f2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

java-client/src/test/java/co/elastic/clients/documentation/getting_started/ConnectingTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public void createClient() throws Exception {
6767

6868
// And create the API client
6969
ElasticsearchClient esClient = new ElasticsearchClient(transport);
70+
71+
// Use the client...
72+
73+
// Close the transport, freeing the underlying thread
74+
transport.close();
7075
//end::create-client
7176

7277
//tag::first-request
@@ -115,6 +120,11 @@ restClient, new JacksonJsonpMapper(), null, esOtelInstrumentation
115120

116121
// And create the API client
117122
ElasticsearchClient esClient = new ElasticsearchClient(transport);
123+
124+
// Use the client...
125+
126+
// Close the transport, freeing the underlying thread
127+
transport.close();
118128
//end::create-client-otel
119129
}
120130

@@ -150,6 +160,11 @@ AuthScope.ANY, new UsernamePasswordCredentials(login, password)
150160
// Create the transport and the API client
151161
ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
152162
ElasticsearchClient client = new ElasticsearchClient(transport);
163+
164+
// Use the client...
165+
166+
// Close the transport, freeing the underlying thread
167+
transport.close();
153168
//end::create-secure-client-cert
154169
}
155170

@@ -185,6 +200,11 @@ AuthScope.ANY, new UsernamePasswordCredentials(login, password)
185200
// Create the transport and the API client
186201
ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
187202
ElasticsearchClient client = new ElasticsearchClient(transport);
203+
204+
// Use the client...
205+
206+
// Close the transport, freeing the underlying thread
207+
transport.close();
188208
//end::create-secure-client-fingerprint
189209
}
190210

0 commit comments

Comments
 (0)