Webflux WebClient retry and Spring Cloud Circuit Breaker Resilience4J Retry pattern walk into a bar
Asked Answered
S

1

6

Would like to ask a question about two technologies.

We first started with an application that has to call other third parties rest API, hence, we used the Webflux WebClient in our SpringBoot Webflux project. So far so good, we had a successful app for a while.

Then the third party app (not ours) started to become flaky, sometimes will fail on our requests. We had to implement some kind of retry logic. After the implementation of the retry logic, such as WebClient reties, the business flow is now working fine. We mainly took logics from the framework directly. For instance, a talk from @simon-baslé, Cancel, Retry and Timeouts at the recent SpringOne gave many working examples.

.retryWhen(backoff(5, Duration.ofMillis(10).maxbackOff(Duration.ofSeconds(1)).jitter(0.4)).timeout(Duration.ofSeconds(5)

On the other hand, lately, there are more and more apps moving towards Circuit Breaker pattern. The Spring Cloud Circuit Breaker project, backed by Resilience4J is a popular implementation using Resilience4J for patterns such as Circuit Breaker, Bulkhead, and of course Retry.

Hence, I am having a question, is there a benefit of using/combining both in terms of retry?

Any gain in terms of having the two together? Any drawbacks?

Or only one of the two is enough, in which case, which one please? And why?

Thank you

Somehow answered 24/9, 2020 at 17:5 Comment(0)
P
11

we (Resilience4j Team) have implemented custom Spring Reactor operators for CircuitBreaker, Retry and Timeout. Internally Retry and Timeout use operators from Spring Reactor, but Resilience4j adds functionality on top of it:

  1. External configuration of Retry, Timeout and CircuitBreaker via config files
  2. Spring Cloud Config support to dynamically adjust the configuration
  3. Metrics, metrics, metrics ;)

Please see https://resilience4j.readme.io/docs/examples-1 and https://resilience4j.readme.io/docs/getting-started-3

You can even use Annotations to make it more simple:

@CircuitBreaker(name = BACKEND)
@RateLimiter(name = BACKEND)
@Retry(name = BACKEND)
@TimeLimiter(name = BACKEND, fallbackMethod = "fallback")
public Mono<String> method(String param1) {
    return ...
}

private Mono<String> fallback(String param1, TimeoutException ex) {
    return ...;
}

Please be aware that we are providing our own Spring Boot starter. I'm NOT talking about the Spring Cloud CircuitBreaker project.

Phosphatase answered 25/9, 2020 at 6:35 Comment(1)
Does BACKEND in "@CircuitBreaker(name = BACKEND)" mean "backendA" as mentioned in the YAML file in the example resilience4j.readme.io/docs/getting-started-3?Paedo

© 2022 - 2024 — McMap. All rights reserved.