我正在尝试将resilience4j添加到我的应用程序中以实现指数回退等功能。
服务
@Component
public class ResilienceService {
private static final String BACKEND_A = "backendA";
public ResilienceService() throws IOException {
testRetry();
}
@Retry(name = BACKEND_A)
public void testRetry() throws IOException {
System.out.println("Hey it's working!");
throw new IOException();
}
}配置
resilience4j.retry.instances.backendA.maxAttempts=3
resilience4j.retry.instances.backendA.waitDuration=10s
resilience4j.retry.instances.backendA.enableExponentialBackoff=true
resilience4j.retry.instances.backendA.exponentialBackoffMultiplier=2
resilience4j.retry.instances.backendA.retryExceptions[0]=java.io.IOException我试着基本上看看resilience lib是否会调用这个函数3次。我应该如何正确地配置它,并测试重试是否实际发生?我以为我可以在方法上设置一个断点,然后看到它被调用3次,但也许我误解了。
发布于 2021-07-16 08:54:17
除了上面@M.Deinum的评论之外,你可能还被resilience4j-springboot2发现了默认情况下不依赖spring aop。
例如,你可能需要:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
</dependencies>公平地说,the documentation does state
将Resilience4j的Spring Boot2启动器添加到您的编译依赖项中。
该模块期望在运行时中已经提供了org.springframework.boot:spring-boot-starter-actuator和org.springframework.boot:spring-boot-starter-aopare
https://stackoverflow.com/questions/68383305
复制相似问题