spring-cloud / spring-cloud-circuitbreaker

Spring Cloud Circuit Breaker API and Implementations
Apache License 2.0
329 stars 110 forks source link

Properties-based configuration example for resilience4j? #122

Closed eduardolbueno closed 2 years ago

eduardolbueno commented 2 years ago

I'm having difficulty setting up a CB with properties-based configuration. I'm using the spring-cloud BOM version 2020.0.4 which has PR #88 included, along with Spring Boot 2.5.6

Let's say I configure an OpenFeign client, like so:

@FeignClient(name = "customer-service")
public interface CustomerServiceClient {
    @GetMapping("customers/{id}")
    Customer getCustomer(@RequestParam("id") String id);
}

If I include spring-cloud-starter-circuitbreaker-resilience4j in the classpath and enable the circuitbreaker through feign.circuitbreaker.enabled=true, the CB will be auto-configured.

So, first question: what is the name of the resilience4j instance that will be created in this case? Looking at the Resilience4JConfigBuilder class, it's building a CB with the id HardCodedTarget#getCustomer(String). Is that id supposed to be the equivalent to the resilience4j instance?

Adding @CircuitBreaker(name = "customer-service") either to the feign class or the method yields no effect on that id. I want to be able to configure this CB through properties like so, for example: resilience4j.timelimiter.instances.customer-service.timeout-duration=10s

I guess that was the point of #88, after all. So it would be really nice to have a working example.

ctlove0523 commented 2 years ago

@eduardolbueno please support one simple example to reproduce this issue,thanks.

eduardolbueno commented 2 years ago

Sorry for the late response. Here's the example.

demo.zip

ryanjbaxter commented 2 years ago

This has already been fixed in OpenFeign and will be in the next Spring Cloud release https://github.com/spring-cloud/spring-cloud-openfeign/issues/606