Resilience4j 如何路由到回退方法,然后在特定时间后返回到原始方法
我正在使用resilience4j和spring boot,
我需要完成以下场景,
- 当我在originalMethod中失败时
- ,经过5次尝试路由到fallback方法后
- ,在特定的情况下大约5分钟的时间返回到原始方法,
我尝试了重试,如下所示,但不适合问题,
@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 ";
}
添加了属性
resilience4j.retry:
instances:
retryService:
maxRetryAttempts: 5
waitDuration: 50000
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为当达到故障限制时,您可以使用断路器来实现您想要的行为。
通过添加 @CircuitBreaker(...) 注释并指定 failureRateThreshold、waitDurationInOpenState 以及该实例的其他所需的配置属性。
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.