File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed
src/main/java/frodez/config/aop/request Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -26,10 +26,10 @@ public class LimitUserAOP {
2626
2727 @ Around ("@annotation(frodez.config.aop.request.annotation.Limit)" )
2828 public Object limit (ProceedingJoinPoint point ) throws Throwable {
29+ Limit limit = AspectUtil .annotation (point , Limit .class );
2930 RateLimiter limiter = limitCache .computeIfAbsent (ContextUtil .request ().getRequestURI (), i -> RateLimiter .create (
30- AspectUtil .annotation (point , Limit .class ).value ()));
31- //默认请求时长的100倍
32- if (!limiter .tryAcquire ((long ) (100 * 1000 / limiter .getRate ()), DefTime .UNIT )) {
31+ limit .value ()));
32+ if (!limiter .tryAcquire (limit .timeout (), DefTime .UNIT )) {
3333 return Result .fail ("请求超时" );
3434 }
3535 return point .proceed ();
Original file line number Diff line number Diff line change 1919 // 每秒每token限制请求数,默认值100.0
2020 double value () default 100.0 ;
2121
22+ // 超时时间,默认值1000毫秒
23+ long timeout () default 3000 ;
24+
2225}
You can’t perform that action at this time.
0 commit comments