@CircuitBreaker annotation does not works with a @FeignClient annotation
See original GitHub issueHi,
I have created a FeignClient (using resilience4j-spring-boot2 and resilience4j-feign) as follows
@FeignClient(name = "myFeignClient", url = "localhost:8080/resilience4j")
@CircuitBreaker(name = "MyFeignClient", fallbackMethod = "fallBack")
public interface MyFeignClient {
@GetMapping(path = "/errorAlways")
String feignMessage();
default String fallBack() {
return "This is a fallback";
}
}
And I have used the following properties in application.yml
configs:
default:
registerHealthIndicator: true
ringBufferSizeInClosedState: 4
ringBufferSizeInHalfOpenState: 2
automaticTransitionFromOpenToHalfOpenEnabled: true
waitDurationInOpenState: 20s
failureRateThreshold: 50
eventConsumerBufferSize: 10
ignoreExceptions:
- com.resilience4j.exception.BusinessException
The issue is that the @CircuitBreaker
annotation have no impact when I keep it on my FeignClient. But if I create a normal Spring configuration like below, the circuit breaking operations works fine:
@Bean
public MyFeignClient myFeignClient() {
CircuitBreaker circuitBreaker = CircuitBreaker.of("myFeignClient", CircuitBreakerConfig.custom()
.ringBufferSizeInClosedState(4)
.failureRateThreshold(50)
.ringBufferSizeInHalfOpenState(2)
.waitDurationInOpenState(Duration.ofSeconds(20))
.build());
FeignDecorators decorators = FeignDecorators.builder()
.withCircuitBreaker(circuitBreaker)
.withFallback(MyFeignClient.class)
.build();
return Resilience4jFeign.builder(decorators).contract(new SpringMvcContract())
.target(MyFeignClient.class, "http://localhost:8080/resilience4j");
}
Is it a bug with @CircuitBreaker
annotation or it is designed to be used this way only?
PS: Please note that the annotation works perfectly fine when I use it on any normal service class.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Spring Cloud Circuit Breaker: Feign doesn't open circuit breaker
Circuit breaker works, fallback is called, but circuit breaker doesn't change it's state and every time send request to failed service.
Read more >Spring Cloud OpenFeign
In the @FeignClient annotation the String value ("stores" above) is an arbitrary client name, which is used to create a Spring Cloud LoadBalancer...
Read more >Spring Cloud Circuit Breaker Implementation Using ... - Medium
The case is I want to set default config according to my needs that applied to all Reactive Feign Client.
Read more >Circuit breaker implementation in spring boot2
As of now there is no annotation support of resilience4j with openfeign library for ex. like the annotation @FeignClient provided by spring ...
Read more >Setup a Circuit Breaker with Hystrix, Feign Client and Spring ...
To create a client to consume an HTTP service, creating an interface annotated with @FeignClient is necessary. Endpoints can be declared in ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, the annotation can’t be used together with Feign, at the moment…
You can only use Resilience4jFeign in your code. But you should inject the CircuitBreakerRegistry to retrieve a CircuitBreaker instance. That way you can still configure the CircuitBreakers in your Spring Boot application.yml file.
Submitted the PR here