弹性4j - 重试具有多个等待持续时间的自定义间隔函数?



Resilience4j 版本:1.4.0 Java版本:11

我想实现这里提到的确切事情:https://resilience4j.readme.io/docs/retry#use-a-custom-intervalfunction

如果您不想在重试尝试之间使用固定的等待持续时间,则可以配置一个 IntervalFunction,该函数用于计算每次尝试的等待持续时间。

我们需要在yml文件中配置它吗?还是我们需要覆盖IntervalFunction? 我需要以指数方式重试 3 次,每次重试都有不同的等待时间,例如:第一次重试应在 30 秒后,第二次重试应在 45 分钟后,第三次重试应在 2 小时后。在哪里配置这些时间戳?我是新手,请指教。

服务等级:

@Retry(name = "retryService1", fallbackMethod = "retryfallback")
@Override
public String customerRegistration(DTO dto) throws ExecutionException, InterruptedException {
String response = restTemplate("/register/customer", dto, String.class); // this throws 500 error code
return response ;
}
public String retryfallback(DTO dto, Throwable t) {
logger.error("Inside retryfallback, cause - {} {}", t.toString(), new Date());
return "Inside retryfallback method. Some error occurred while calling service for customer registration";
}

应用程序.yml

resilience4j.retry.instances:
retryService1:
maxRetryAttempts: 3
waitDuration: 10s
enableExponentialBackoff: true
exponentialBackoffMultiplier: 2

谢谢。

目前只能通过使用RetryConfigCustomizer来实现。

@Bean
public RetryConfigCustomizertestCustomizer() {
return RetryConfigCustomizer
.of("retryService1", builder -> builder.intervalFunction(intervalWithExponentialBackoff));
}

最新更新