呼叫不会成为Resilience4断路器的后备方法

时间:2020-07-06 04:03:23

标签: spring spring-boot circuit-breaker resilience4j

我正在使用Resilience4j断路器版本:'1.4.0与Spring Boot版本2.0.6,我的问题是-后备方法不起作用。调用不会转到fallback方法。 下面是我的代码:

@Override
@CircuitBreaker(name="mainService",fallbackMethod = "callFallback")
public JSONObject callService(JSONObject rawRequest) throws TimeoutException {
      ...
       throw new TimeoutException("Time occured while calling 
       service");
      ...
}

-和后备方法:

private JSONObject callFallback(JSONObject rawRequest,Throwable t){

    System.out.println("Inside fallback method callNsFallback, 
        cause"+t.toString());

        logger.info("Inside fallback method callFallback, 
        cause - {}",t.toString());

    return rawRequest;
}

-application.yml中的配置

resilience4j:
circuitbreaker:
    configs:
    default:
        registerHealthIndicator: true
        ringBufferSizeInClosedState: 5
        ringBufferSizeInHalfOpenState: 3
        slidingWindowSize: 10
        minimumNumberOfCalls: 5
        permittedNumberOfCallsInHalfOpenState: 3
        automaticTransitionFromOpenToHalfOpenEnabled: true
        waitDurationInOpenState: 1s
        failureRateThreshold: 50
        eventConsumerBufferSize: 10
        recordExceptions:
        - java.util.concurrent.TimeoutException
    instances:
    mainService:
        baseConfig: default

0 个答案:

没有答案