Sentinel annotation supports method name as default resource name (#187)
This commit is contained in:
parent
85c844eb9c
commit
078df9db4f
|
|
@ -37,7 +37,7 @@ public @interface SentinelResource {
|
|||
/**
|
||||
* @return name of the Sentinel resource
|
||||
*/
|
||||
String value();
|
||||
String value() default "";;
|
||||
|
||||
/**
|
||||
* @return the entry type (inbound or outbound), outbound by default
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class SentinelResourceAspect {
|
|||
// Should not go through here.
|
||||
throw new IllegalStateException("Wrong state for SentinelResource annotation");
|
||||
}
|
||||
String resourceName = annotation.value();
|
||||
String resourceName = getResourceName(annotation.value(), originMethod);
|
||||
EntryType entryType = annotation.entryType();
|
||||
Entry entry = null;
|
||||
try {
|
||||
|
|
@ -76,7 +76,28 @@ public class SentinelResourceAspect {
|
|||
ContextUtil.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getResourceName(String resourceName, Method method) {
|
||||
if(StringUtil.isNotBlank(resourceName)){
|
||||
return resourceName;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append(method.getDeclaringClass().getName())
|
||||
.append(":")
|
||||
.append(method.getName())
|
||||
.append("(");
|
||||
boolean isFirst = true;
|
||||
for (Class<?> clazz : method.getParameterTypes()) {
|
||||
if (!isFirst) {
|
||||
buf.append(",");
|
||||
}
|
||||
buf.append(clazz.getName());
|
||||
isFirst = false;
|
||||
}
|
||||
buf.append(")");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private Object handleBlockException(ProceedingJoinPoint pjp, SentinelResource annotation, BlockException ex)
|
||||
throws Exception {
|
||||
// Execute fallback for degrading if configured.
|
||||
|
|
|
|||
Loading…
Reference in New Issue