|
18 | 18 | package org.dromara.dynamictp.extension.limiter.redis.ratelimiter;
|
19 | 19 |
|
20 | 20 | import lombok.extern.slf4j.Slf4j;
|
| 21 | +import org.dromara.dynamictp.common.entity.NotifyItem; |
21 | 22 | import org.dromara.dynamictp.common.pattern.filter.Invoker;
|
22 | 23 | import org.dromara.dynamictp.core.notifier.chain.filter.NotifyFilter;
|
23 | 24 | import org.dromara.dynamictp.core.notifier.context.BaseNotifyCtx;
|
@@ -45,13 +46,21 @@ public int getOrder() {
|
45 | 46 | }
|
46 | 47 |
|
47 | 48 | @Override
|
48 |
| - public void doFilter(BaseNotifyCtx context, Invoker<BaseNotifyCtx> nextFilter) { |
49 |
| - String notifyName = context.getExecutorWrapper().getThreadPoolName() + "#" + context.getNotifyItemEnum().getValue(); |
50 |
| - int silencePeriod = context.getNotifyItem().getSilencePeriod(); |
51 |
| - int clusterLimit = context.getNotifyItem().getClusterLimit(); |
52 |
| - boolean checkResult = redisScriptRateLimiter.check(notifyName, silencePeriod, clusterLimit); |
53 |
| - if (checkResult) { |
54 |
| - nextFilter.invoke(context); |
| 49 | + public void doFilter(BaseNotifyCtx context, Invoker<BaseNotifyCtx> nextInvoker) { |
| 50 | + if (tryPass(context)) { |
| 51 | + nextInvoker.invoke(context); |
55 | 52 | }
|
56 | 53 | }
|
| 54 | + |
| 55 | + private boolean tryPass(BaseNotifyCtx context) { |
| 56 | + // silence period <= 0 indicates that no rate limit check is required. |
| 57 | + NotifyItem notifyItem = context.getNotifyItem(); |
| 58 | + if (notifyItem.getSilencePeriod() <= 0) { |
| 59 | + return true; |
| 60 | + } |
| 61 | + String notifyName = context.getExecutorWrapper().getThreadPoolName() + "#" + context.getNotifyItemEnum().getValue(); |
| 62 | + int silencePeriod = notifyItem.getSilencePeriod(); |
| 63 | + int clusterLimit = notifyItem.getClusterLimit(); |
| 64 | + return redisScriptRateLimiter.tryPass(notifyName, silencePeriod, clusterLimit); |
| 65 | + } |
57 | 66 | }
|
0 commit comments