提交 | 用户 | 时间
|
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 cn.hutool.system.SystemUtil; |
|
6 |
import com.iailab.framework.ratelimiter.core.annotation.RateLimiter; |
|
7 |
import com.iailab.framework.ratelimiter.core.keyresolver.RateLimiterKeyResolver; |
|
8 |
import org.aspectj.lang.JoinPoint; |
|
9 |
|
|
10 |
/** |
|
11 |
* Server 节点级别的限流 Key 解析器,使用方法名 + 方法参数 + IP,组装成一个 Key |
|
12 |
* |
|
13 |
* 为了避免 Key 过长,使用 MD5 进行“压缩” |
|
14 |
* |
|
15 |
* @author iailab |
|
16 |
*/ |
|
17 |
public class ServerNodeRateLimiterKeyResolver implements RateLimiterKeyResolver { |
|
18 |
|
|
19 |
@Override |
|
20 |
public String resolver(JoinPoint joinPoint, RateLimiter rateLimiter) { |
|
21 |
String methodName = joinPoint.getSignature().toString(); |
|
22 |
String argsStr = StrUtil.join(",", joinPoint.getArgs()); |
|
23 |
String serverNode = String.format("%s@%d", SystemUtil.getHostInfo().getAddress(), SystemUtil.getCurrentPID()); |
|
24 |
return SecureUtil.md5(methodName + argsStr + serverNode); |
|
25 |
} |
|
26 |
|
|
27 |
} |