Client using a pool of HTTP clients targeting each a single IP. Each of them is refreshed based on HTTP health check and DNS query. It has the following features.
- Client side load balancing between all the IP behind the hostname
- Monitoring of all the IP behind the hostname at HTTP level
- Monitoring of the DNS
- TCP failover
- HTTP/2 with seamless fallback to HTTP/1
A presentation detailing the features of the client and comparing it with other Java HTTP clients (HttpUrlConnection, Apache, Jetty) Presentation.
HttpClientPool singletonByHost = HttpClientPool.newHttpClientPool(new ServerConfiguration("openjdk.java.net"));
java.net.http.HttpClient resilientClient = singletonByHost.resilientClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://openjdk.java.net/"))
.build();
resilientClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();