0

I am looking at the Spring Cloud Circuit Breaker example with respect to using a Reactive API. I understand the basics and how the fallback mechanism works for WebClient but can't see how to implement a fail-fast solution for when the circuit breaker is open.

This would be the example method I would like to make 'fail-fast' (taken from the article).

public Mono<String> slow() {
        return webClient.get().uri("/slow").retrieve()
                .bodyToMono(String.class).transform(it -> {
            CircuitBreaker cb = cbFactory.create("slow");
            return cb.run(it, throwable -> 
                            Mono.just("fallback"));
                });
    }

Any help or insight into this much appreciated.

  • 2
    I don't understand what you mean. There's not a separate handler for circuit open, just the fallback. – spencergibb Jun 02 '19 at 16:52
  • That is sort of my point. The code example in the documentation shows the fallback mechanism but does not discuss how circuit open/close is implemented and acts. – Jack of Shadows Jun 02 '19 at 22:58
  • The fallback is called if the circuit is open. – spencergibb Jun 03 '19 at 02:05
  • Ok, let me rephrase this. Normally the circuit breaker wraps an operation that may fail.so it can handle fail fast on entry and failures to fallback. An example would be using @HystrixCommand in Spring which wraps the operation in a proxy. What I'm not seeing in the reactive examples is the operation to fail fast before an attempt is made to execute the operation. Ignore the fallback as this isn't the the part I'm trying to understand. – Jack of Shadows Jun 03 '19 at 22:34
  • If the circuit is open, the operation is not tried. The circuit breaker just wraps hystrix or resilience 4j. They don't operate any differently – spencergibb Jun 04 '19 at 02:05

0 Answers0