title: Resilience4j never call fallback method
body: <p>I am new to Resilience4j and circuit breaker pattern.</p>
  <p>I write a sample for resilience4j. Details is as below:</p>
  <p>pom.xml:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;2.3.2.RELEASE&lt;/version&gt;
      &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
  &lt;/parent&gt;
  &lt;groupId&gt;ir.co.isc&lt;/groupId&gt;
  &lt;artifactId&gt;circuit-breaker&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;circuit-breaker&lt;/name&gt;
  &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
  &lt;properties&gt;
      &lt;java.version&gt;11&lt;/java.version&gt;
      &lt;spring-cloud.version&gt;Hoxton.SR6&lt;/spring-cloud.version&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;!-- resilience4j dependency--&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.github.resilience4j&lt;/groupId&gt;
          &lt;artifactId&gt;resilience4j-spring-boot2&lt;/artifactId&gt;
          &lt;version&gt;1.5.0&lt;/version&gt;
          &lt;type&gt;pom&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-aop&lt;/artifactId&gt;
          &lt;version&gt;2.3.0.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
          &lt;version&gt;2.3.2.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                  &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;dependencyManagement&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
              &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
              &lt;type&gt;pom&lt;/type&gt;
              &lt;scope&gt;import&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/dependencyManagement&gt;
  
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p>application.yml:</p>
  <pre><code>resilience4j:
  circuitbreaker:
      configs:
          default:
              registerHealthIndicator: true
              slidingWindowSize: 10
              minimumNumberOfCalls: 5
              permittedNumberOfCallsInHalfOpenState: 3
              automaticTransitionFromOpenToHalfOpenEnabled: true
              waitDurationInOpenState: 5s
              failureRateThreshold: 20
              eventConsumerBufferSize: 10
      instances:
          mainService:
              baseConfig: default
  </code></pre>
  <p>Controller class:</p>
  <pre><code>package ir.co.isc.circuitbreaker;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.ResponseStatus;
  import org.springframework.web.bind.annotation.RestController;
  
  @RestController
  public class MainServiceController {
  
  
  @Autowired
  private MainService mainService;
  
  
  @GetMapping(&quot;/getSleuthTest&quot;)
  @ResponseStatus(HttpStatus.OK)
  public ResponseEntity&lt;String&gt; getSleuthTest(){
      String response = mainService.getResponse();
      return new ResponseEntity&lt;&gt;(response, HttpStatus.OK);
    }
   }
  </code></pre>
  <p>Service class:</p>
  <pre><code>package ir.co.isc.circuitbreaker;
  
  import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Bean;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.stereotype.Service;
  import org.springframework.web.client.RestTemplate;
  
  @Service
  public class MainService {
  
  private static final String MAIN_SERVICE = &quot;mainService&quot;;
  
  @Autowired
  private RestTemplate restTemplate;
  
  @Bean
  public RestTemplate getRestTemplate() {
      return new RestTemplate();
  }
  
  @CircuitBreaker(name = MAIN_SERVICE, fallbackMethod=&quot;testFallBack&quot;)
  public String getResponse(){
      return restTemplate.getForObject(&quot;http://localhost:8081/serviceOne&quot;, String.class);
  }
  
  private ResponseEntity&lt;String&gt; testFallBack(Exception e){
      return new ResponseEntity&lt;&gt;(&quot;In fallback method&quot;, HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }
  </code></pre>
  <p>SpringBootApplication class:</p>
  <pre><code>package ir.co.isc.circuitbreaker;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class CircuitBreakerApplication {
  
  public static void main(String[] args) {
      SpringApplication.run(CircuitBreakerApplication.class, args);
     }
  
  }
  </code></pre>
  <p>I use postman runner to call my API. I set runner iterations to 200.
  after 10 successful API call I stop third-party in this url :
  http://localhost:8081/serviceOne</p>
  <p>As I understood, after stopping third party API and record minimum number of successful call, resilience4j start to calculate fault rate and when fault rate is more than failureRateThreshold, fallback method (here testFallBack in service class) called, circuit status change from close to open mode and return my desire answer which describe in testFallBack() method.</p>
  <p>But this is never happen (testFallBack() method never called). What is wrong with my application?</p>