use of io.github.resilience4j.ratelimiter.annotation.RateLimiter in project resilience4j by resilience4j.
the class RateLimiterAspect method rateLimiterAroundAdvice.
@Around(value = "matchAnnotatedClassOrMethod(limitedService)", argNames = "proceedingJoinPoint, limitedService")
public Object rateLimiterAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, RateLimiter limitedService) throws Throwable {
RateLimiter targetService = limitedService;
Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
String methodName = method.getDeclaringClass().getName() + "#" + method.getName();
if (targetService == null) {
targetService = getRateLimiterAnnotation(proceedingJoinPoint);
}
String name = targetService.name();
io.github.resilience4j.ratelimiter.RateLimiter rateLimiter = getOrCreateRateLimiter(methodName, name);
return handleJoinPoint(proceedingJoinPoint, rateLimiter, methodName);
}
use of io.github.resilience4j.ratelimiter.annotation.RateLimiter in project resilience4j by resilience4j.
the class RateLimiterAspect method getRateLimiterAnnotation.
private RateLimiter getRateLimiterAnnotation(ProceedingJoinPoint proceedingJoinPoint) {
RateLimiter rateLimiter = null;
Class<?> targetClass = proceedingJoinPoint.getTarget().getClass();
if (targetClass.isAnnotationPresent(RateLimiter.class)) {
rateLimiter = targetClass.getAnnotation(RateLimiter.class);
if (rateLimiter == null) {
rateLimiter = targetClass.getDeclaredAnnotation(RateLimiter.class);
}
if (rateLimiter == null) {
logger.debug("TargetClass has no declared annotation 'RateLimiter'");
}
}
return rateLimiter;
}
Aggregations