'httpclient with retry and circuit breaker as a additional capability

I am trying to create httpclient with retry and circuit breaker as a additional capability.

I can add retryhandler to httpcleint like below but not able to add circuitBreaker to httpclient. (I am using java 8)

public CloseableHttpClient createClient(){
    CloseableHttpClient httpclient = HttpClients.custom().setRetryHandler(new HttpRequestRetryHandler() {
        @Override
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            log.debug("retryRequest "+executionCount);
            return executionCount <= Constants.MAX_RETRIES ;
        }
    }).build();

    return httpclient;
}

any leads on this will be much appreciated .



Solution 1:[1]

I will have to keep my answer brief because I myself interacted with such a problem very recently. One thing that can help you is to make use of Hystrix Command Circuit Breaker Pattern.

It is a library written by Netflix where you can wrap your HTTP calls around a Hystrix command and it helps you to add circuit breaking, fallback functionality among others.

Here is a blog that could be a starter for you: https://howtodoinjava.com/spring-cloud/spring-hystrix-circuit-breaker-tutorial/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mudit Choraria