当前位置:网站首页>[micro service sentinel] sentinelresourceaspect details
[micro service sentinel] sentinelresourceaspect details
2022-07-01 23:12:00 【Bulst】
List of articles
AOP
As we mentioned above @SentinelResource annotation , We all know that annotation is just a mark , Then the real realization of current limiting logic is AOP 了 .
AOP What business problems will be solved in the actual development ?
Transaction related
Used to rollback thingsPerformance monitoring
Record the call time before and after the method call , Method execution too long or timeout alarm .The caching proxy
Cache the return value of a method , The next time you execute this method , Get it directly from the cache .Software cracking
Use AOP Modify the judgment logic of the verification class of the software .Log
Record system logs before and after method execution .Workflow system
Workflow system needs to mix business code and process engine code to execute , Then we can use AOP Separate it , And dynamically connect services .Authority verification
Verify that you have permission to execute the current method before executing the method , If not, throw an exception without permission , Captured by business code .
Next , Let's take a look at its source code com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect
Source code
@Aspect
public class SentinelResourceAspect extends AbstractSentinelAspectSupport {
@Pointcut("@annotation(com.alibaba.csp.sentinel.annotation.SentinelResource)")
public void sentinelResourceAnnotationPointcut() {
}
@Around("sentinelResourceAnnotationPointcut()")
public Object invokeResourceWithSentinel(ProceedingJoinPoint pjp) throws Throwable {
Method originMethod = resolveMethod(pjp);
SentinelResource annotation = originMethod.getAnnotation(SentinelResource.class);
if (annotation == null) {
// Should not go through here.
throw new IllegalStateException("Wrong state for SentinelResource annotation");
}
String resourceName = getResourceName(annotation.value(), originMethod);
EntryType entryType = annotation.entryType();
int resourceType = annotation.resourceType();
Entry entry = null;
try {
entry = SphU.entry(resourceName, resourceType, entryType, pjp.getArgs());
Object result = pjp.proceed();
return result;
} catch (BlockException ex) {
return handleBlockException(pjp, annotation, ex);
} catch (Throwable ex) {
Class<? extends Throwable>[] exceptionsToIgnore = annotation.exceptionsToIgnore();
// The ignore list will be checked first.
if (exceptionsToIgnore.length > 0 && exceptionBelongsTo(ex, exceptionsToIgnore)) {
throw ex;
}
if (exceptionBelongsTo(ex, annotation.exceptionsToTrace())) {
traceException(ex);
return handleFallback(pjp, annotation, ex);
}
// No fallback function can handle the exception, so throw it out.
throw ex;
} finally {
if (entry != null) {
entry.exit(1, pjp.getArgs());
}
}
}
}
Source code analysis
Let's analyze this code :
- Use aspect Of around Intercept , Interception is marked with SentinelResource Annotations
- Call before you enter the method SphU.entry(resourceName, entryType), Call after completion entry.exit();
- Call... In case of exception handleBlockException Method
This also verifies our previous article , Two solutions for exception handling in annotations .
边栏推荐
- Turn -- go deep into Lua scripting language, so that you can thoroughly understand the debugging principle
- Force buckle 710 Random numbers in the blacklist
- 力扣 710. 黑名单中的随机数
- Wechat personal small store one click opening assistant applet development
- Jielizhi Bluetooth headset quality control and production skills [chapter]
- Redis~02 缓存:更新数据时如何保证MySQL和Redis中的数据一致性?
- 建模和影视后期有什么关联?
- Simple interactive operation of electron learning (III)
- 想请教一下,证券开户选择哪个证券比较好?手机开户是安全么?
- [JUC learning road day 8] condition
猜你喜欢

【微服务|Sentinel】sentinel整合openfeign

正则系列之组和范围(Groups and Ranges)

思科考试--冗余网络

The online beggar function of Japanese shopping websites
![Jielizhi Bluetooth headset quality control and production skills [chapter]](/img/3e/571d246d211a979e948dae1de56e93.png)
Jielizhi Bluetooth headset quality control and production skills [chapter]

Programming English vocabulary notebook

RPA: Bank digitalization, business process automation "a small step", and loan review efficiency "a big step"

软件测试之「 性能测试」总结,新手上路必会知识点

"35 years old, the boss of the company, with a monthly salary of 20000, give away takeout": the times abandoned you, not even saying goodbye

2022安全员-C证考试题模拟考试题库及模拟考试
随机推荐
Programming English vocabulary notebook
Detailed explanation of twenty common software testing methods (the most complete in History)
第三方验收测试有什么好处?专业第三方软件测试机构推荐
YOGA27多维一体电脑,兼具出色外观与高端配置
【微服务|Sentinel】@SentinelResource详解
众昂矿业:发展以氟化工为主的特色化工产业具有先天优势
Advanced skills of testers: a guide to the application of unit test reports
2022年危险化学品经营单位安全管理人员考试题及在线模拟考试
leetcode - 287. Find duplicates
[MySQL] index creation, viewing and deletion
URL 介绍
Explain the use of locksupport in detail
Jerry's records are powered by Vbat with a power supply voltage of 4.2V [chapter]
工作中非常重要的测试策略,你大概没注意过吧
Preparation of functional test report
Wechat personal small store one click opening assistant applet development
Cloud Vulnerability Global Database
[kotlin third party] coil koltin collaboration picture loading library coil glide like picture loading third party
window10安装wsl(一)(WslRegisterDistribution ERROR)
Deadlock handling strategies - prevent deadlock, avoid deadlock, detect and remove deadlock