提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.ratelimiter.core.keyresolver.impl; |
H |
2 |
|
|
3 |
import cn.hutool.core.util.StrUtil; |
|
4 |
import cn.hutool.crypto.SecureUtil; |
|
5 |
import com.iailab.framework.ratelimiter.core.annotation.RateLimiter; |
|
6 |
import com.iailab.framework.ratelimiter.core.keyresolver.RateLimiterKeyResolver; |
|
7 |
import org.aspectj.lang.JoinPoint; |
|
8 |
|
|
9 |
/** |
|
10 |
* 默认(全局级别)限流 Key 解析器,使用方法名 + 方法参数,组装成一个 Key |
|
11 |
* |
|
12 |
* 为了避免 Key 过长,使用 MD5 进行“压缩” |
|
13 |
* |
|
14 |
* @author iailab |
|
15 |
*/ |
|
16 |
public class DefaultRateLimiterKeyResolver implements RateLimiterKeyResolver { |
|
17 |
|
|
18 |
@Override |
|
19 |
public String resolver(JoinPoint joinPoint, RateLimiter rateLimiter) { |
|
20 |
String methodName = joinPoint.getSignature().toString(); |
|
21 |
String argsStr = StrUtil.join(",", joinPoint.getArgs()); |
|
22 |
return SecureUtil.md5(methodName + argsStr); |
|
23 |
} |
|
24 |
|
|
25 |
} |