java - 使用resilience4j 实现节流/去抖动
问题描述
我的问题是如何使用resilience4j 库实现(配置)throttlig。我尝试在下一个配置中使用 RateLimiter:
RateLimiter rateLimiter = RateLimiterRegistry.of(
RateLimiterConfig.custom()
.limitRefreshPeriod(Duration.ofSeconds(10))
.limitForPeriod(1)
.timeoutDuration(Duration.ofSeconds(5))
.build()
).rateLimiter("default");
Runnable ratedCall = RateLimiter.decorateRunnable(rateLimiter, () -> { /*business logic here*/ });
// and then
try {
ratedCall.run();
} catch (Exception e) {
LOG.warn(e);
}
但它不会阻止(忽略)后续方法调用。我需要实现的是,我的特定方法不能在 10 秒内被调用超过一次,无论是否有任何可能的异常。
请指教!
谢谢!
解决方案
推荐阅读
- java-8 - 方法参考 - 将函数传递给具有消费者参数的方法
- javascript - 从父元素中删除类 ID
- netbeans - How do I run NetBeans JUnit tests from the command line?
- sql - list of months error
- mysql - REST API 主键设计 MySQL
- node.js - Gulp 任务导致我的节点进程挂起
- excel - siebel使用vba宏编译?
- mysql - 如果更新后全部为空,则mysql删除行而没有触发
- php - Php For Loop 提供额外的迭代
- excel - 复制单元格值并粘贴到列表/表格中的另一个工作表