question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@CircuitBreaker annotation does not works with a @FeignClient annotation

See original GitHub issue

Hi,

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:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
RobWincommented, Aug 12, 2019

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.

0reactions
harishmbmcommented, Aug 17, 2019

Submitted the PR here

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found