【发布时间】:2022-01-05 11:53:40
【问题描述】:
我似乎无法让 Resilience4j @RateLimiter 与 Spring Boot 一起使用。
下面是代码
@Log4j2
@Component
class Resilience4jDemo implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
for (int i = 0; i < 100; i++) {
callBackendA();
}
}
@RateLimiter(name = "backendA")
private void callBackendA() {
log.info("Calling ");
}
}
application.yaml 文件
resilience4j.ratelimiter:
instances:
backendA:
limitForPeriod: 1
limitRefreshPeriod: 10s
timeoutDuration: 0
pom.xml
<!-- https://mvnrepository.com/artifact/io.github.resilience4j/resilience4j-spring-boot2 -->
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot2</artifactId>
<version>1.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-aop -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.6.0</version>
</dependency>
没有进行速率限制。无法弄清楚我错过了什么。
【问题讨论】:
-
这叫做self-call,Spring的AOP都不起作用。
标签: java spring-boot resilience4j