Authored by hugufei

不同方法可以共用一个限流配置

... ... @@ -29,9 +29,9 @@ public class PersionalRateLimitAspect {
@Around("@annotation(com.yoho.search.common.downgrade.persional.PersionalRateLimit)")
public Object persionalRateLimit(ProceedingJoinPoint pjp) throws Throwable {
try {
String persionalRateLimitKey = this.getPersionalRateLimitKey(pjp);
MethodSignature signature = (MethodSignature) pjp.getSignature();
PersionalRateLimit rersionalRateLimit = signature.getMethod().getAnnotation(PersionalRateLimit.class);
String persionalRateLimitKey = this.getPersionalRateLimitKey(rersionalRateLimit, pjp);
Object[] arges = pjp.getArgs();
for (Object object : arges) {
if (this.doPersionalRateLimit(object, rersionalRateLimit, persionalRateLimitKey)) {
... ... @@ -114,7 +114,10 @@ public class PersionalRateLimitAspect {
* @param pjp
* @return
*/
private String getPersionalRateLimitKey(ProceedingJoinPoint pjp) {
private String getPersionalRateLimitKey(PersionalRateLimit rersionalRateLimit, ProceedingJoinPoint pjp) {
if (StringUtils.isNotBlank(rersionalRateLimit.name())) {
return rersionalRateLimit.name();
}
// 1、获取method和class
Method targetMethod = ((MethodSignature) (pjp.getSignature())).getMethod();
Class<?> clazz = targetMethod.getDeclaringClass();
... ... @@ -137,7 +140,7 @@ public class PersionalRateLimitAspect {
if (StringUtils.isNotBlank(classRequestMappingValue) || StringUtils.isNotBlank(methodRequestMappingValue)) {
return classRequestMappingValue + methodRequestMappingValue;
} else {
return clazz.getName() + '_' + targetMethod.getName();
return clazz.getName() + '.' + targetMethod.getName();
}
}
... ...