简体   繁体   中英

Resilience4j How to route to fallback method then return back to original method after specific amount of time

I am working with resilience4j and spring boot,

I need to accomplish the below scenario,

  • When I have a failure in the originalMethod
  • After 5 attempts route to the fallback method
  • After a specific time like 5 minutes return back to the originalMethod

I tried with retry as below but does not fit the problem,

     @Retry(name = "retryService", fallbackMethod = "fallback")
    public String originalMethod(String data) throws InterruptedException {
        //..... call external service 
    }

public String fallback(String data, Throwable t) {
        logger.error("Inside retryfallback, cause – {}", t.toString());
        return "Inside retryfallback method. Some error occurred ";
    }

Added properties

resilience4j.retry:
  instances:
    retryService:
      maxRetryAttempts: 5
      waitDuration: 50000

I think you can use a circuit breaker for sometime when a failure limit reached to achieve the behavior you want.

By adding @CircuitBreaker(...) annotation and specifying the failureRateThreshold, waitDurationInOpenState and the other needed config properties for that instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM