小编vbv*_*bvT的帖子

调用不会调用 Resilience4 断路器的后备方法

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

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

-- 和后备方法:

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;
}
Run Code Online (Sandbox Code Playgroud)

--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:
        - …
Run Code Online (Sandbox Code Playgroud)

spring circuit-breaker spring-boot resilience4j

5
推荐指数
1
解决办法
3844
查看次数