Skip to content

Commit

Permalink
[doc] Extend the example for disabling the connection pool (#2082)
Browse files Browse the repository at this point in the history
Show that with one and the same HttpClient instance, one can
initiate many requests that always will use a new connection.

Related to comment #1828 (comment)
  • Loading branch information
violetagg committed Mar 8, 2022
1 parent 1b64f93 commit 4ceaf84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/asciidoc/http-client-conn-provider.adoc
Expand Up @@ -79,7 +79,7 @@ If you need to disable the connection pool, you can apply the following configur
[source,java,indent=0]
.{examplesdir}/pool/Application.java
----
include::{examplesdir}/pool/Application.java[lines=18..35]
include::{examplesdir}/pool/Application.java[lines=18..49]
----
====

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2021-2022 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,11 +20,25 @@
public class Application {

public static void main(String[] args) {
HttpClient client = HttpClient.newConnection();
HttpClient client =
HttpClient.newConnection()
.doOnConnected(conn -> System.out.println("Connection " + conn.channel()));

String response =
// A new connection is established for every request
client.get()
.uri("https://example.com/")
.uri("https://httpbin.org/get")
.responseContent()
.aggregate()
.asString()
.block();

System.out.println("Response " + response);

response =
// A new connection is established for every request
client.post()
.uri("https://httpbin.org/post")
.responseContent()
.aggregate()
.asString()
Expand Down

0 comments on commit 4ceaf84

Please sign in to comment.