对比新文件 |
| | |
| | | package com.iailab.framework.ratelimiter.core.keyresolver.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.system.SystemUtil; |
| | | import com.iailab.framework.ratelimiter.core.annotation.RateLimiter; |
| | | import com.iailab.framework.ratelimiter.core.keyresolver.RateLimiterKeyResolver; |
| | | import org.aspectj.lang.JoinPoint; |
| | | |
| | | /** |
| | | * Server 节点级别的限流 Key 解析器,使用方法名 + 方法参数 + IP,组装成一个 Key |
| | | * |
| | | * 为了避免 Key 过长,使用 MD5 进行“压缩” |
| | | * |
| | | * @author iailab |
| | | */ |
| | | public class ServerNodeRateLimiterKeyResolver implements RateLimiterKeyResolver { |
| | | |
| | | @Override |
| | | public String resolver(JoinPoint joinPoint, RateLimiter rateLimiter) { |
| | | String methodName = joinPoint.getSignature().toString(); |
| | | String argsStr = StrUtil.join(",", joinPoint.getArgs()); |
| | | String serverNode = String.format("%s@%d", SystemUtil.getHostInfo().getAddress(), SystemUtil.getCurrentPID()); |
| | | return SecureUtil.md5(methodName + argsStr + serverNode); |
| | | } |
| | | |
| | | } |