Giter Site home page Giter Site logo

nhenneaux / resilient-httpclient Goto Github PK

View Code? Open in Web Editor NEW
9.0 4.0 6.0 464 KB

Java HTTP client with pooling and auto refresh of underlying IP addresses

License: GNU Lesser General Public License v3.0

Java 100.00%
java httpclient http2 http dns java-httpclient

resilient-httpclient's Introduction

Resilient HTTP with java.net.http.HttpClient

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

Schema

A presentation detailing the features of the client and comparing it with other Java HTTP clients (HttpUrlConnection, Apache, Jetty) Presentation.

Usage

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();

Build Status Maven Central Quality Gate Status Coverage

resilient-httpclient's People

Contributors

andremoniy avatar hemantworldline avatar marwamohamad avatar nhenneaux avatar sim0ham3d avatar snasib avatar thibaudledent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

resilient-httpclient's Issues

refreshTheListWrappedInTryCatch should not re-throw an exception because it is used in the scheduled executor service

Please observe this javadoc comment for the scheduleAtFixedRate::scheduleAtFixedRate method:

The sequence of task executions continues indefinitely until one of the following exceptional completions occur:
The task is explicitly cancelled via the returned future.
The executor terminates, also resulting in task cancellation.
An execution of the task throws an exception. In this case calling get on the returned future will throw ExecutionException, holding the exception as its cause.

Therefore the HttpClientPool::refreshTheListWrappedInTryCatch method used within
this.scheduledFutureDnsRefresh = scheduledExecutorService.scheduleAtFixedRate( () -> refreshTheListWrappedInTryCatch( dnsLookupWrapper, serverConfiguration, httpClientsCache, singleHttpClientProvider, scheduledExecutorService ), dnsLookupRefreshPeriodInSeconds, dnsLookupRefreshPeriodInSeconds, TimeUnit.SECONDS );

should not re-throw an exception

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.