当前位置:网站首页>Sentinelresource annotation details

Sentinelresource annotation details

2022-06-26 20:11:00 A rookie is a great God

SentinelResource annotation Attribute summary .

> This article is based on Sentinel 1.6.2, theoretical support 1.4.0+

attribute effect Whether must
value Resource name yes
entryTypeentry type , Mark the direction of the flow , Value IN/OUT, The default is OUT no
blockHandler Handle BlockException The function name of . Function requirements :
1. Must be  public
2. The return type is the same as the original method
3. The parameter type needs to match the original method , And add... At the end  BlockException  Parameters of type .
4. By default, it needs to be in the same class as the original method . If you want to use functions of other classes , Configurable  blockHandlerClass , And designate blockHandlerClass The method inside .
no
blockHandlerClass Deposit blockHandler Class . The corresponding processing function must be static modification , Otherwise, it cannot be parsed , Other requirements : Same as blockHandler. no
fallback Used to provide... When an exception is thrown fallback Processing logic .fallback Functions can be used for all types of exceptions ( except  exceptionsToIgnore  The types of exceptions excluded ) To deal with . Function requirements :
1. The return type is the same as the original method
2. The parameter type needs to match the original method ,Sentinel 1.6 Start , Or at the end of the method Add  Throwable  Parameters of type .
3. By default, it needs to be in the same class as the original method . If you want to use functions of other classes , Configurable  fallbackClass , And designate fallbackClass The method inside .
no
fallbackClass【1.6】 Deposit fallback Class . The corresponding processing function must be static modification , Otherwise, it cannot be parsed , Other requirements : Same as fallback. no
defaultFallback【1.6】 For general purpose fallback Logic . Default fallback Functions can be used for all types of exceptions ( except  exceptionsToIgnore  The types of exceptions excluded ) To deal with . If you configure fallback and defaultFallback, With fallback Subject to . Function requirements :
1. The return type is the same as the original method
2. The method parameter list is empty , Or there's a  Throwable  Parameters of type .
3. By default, it needs to be in the same class as the original method . If you want to use functions of other classes , Configurable  fallbackClass , And designate  fallbackClass  The method inside .
no
exceptionsToIgnore【1.6】 Specify which exceptions to exclude . Excluded exceptions are not counted in the exception statistics , And will not enter fallback Logic , It's the same thing . no
exceptionsToTrace need trace It's abnormal Throwable

TIPS
>
> - 1.6.0 Previous version fallback Function is only for degraded exceptions (DegradeException) To deal with , Can't handle business exceptions .
> - if blockHandler and fallback It's all configured , It is degraded by current limiting and thrown  BlockException  It will only enter  blockHandler  Processing logic . If not configured  blockHandlerfallback  and  defaultFallback, When it is degraded by current limiting, it will  BlockException  Direct selling .
> - from 1.4.0 Version start , Annotation method definition resource supports automatic statistics of business exceptions , No manual call required  Tracer.trace(ex)  To record business exceptions .Sentinel 1.4.0 Previous versions needed to call themselves  Tracer.trace(ex)  To record business exceptions .

原网站

版权声明
本文为[A rookie is a great God]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206262007431805.html