当前位置:网站首页>[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 .
边栏推荐
- Jielizhi, production line assembly link [chapter]
- Compare the version number [double pointer to intercept the string you want]
- 数字化转型道阻且长,如何迈好关键的第一步
- Cisco test -- the concept and configuration test of routing
- Advanced skills of testers: a guide to the application of unit test reports
- Happy number [fast and slow pointer of ring PROBLEMS]
- Contents of other parts of the map
- 91. (cesium chapter) cesium rocket launch simulation
- shell 流程控制
- A few minutes before work, I found out V-model and The difference between sync
猜你喜欢

众昂矿业:发展以氟化工为主的特色化工产业具有先天优势
![Happy number [fast and slow pointer of ring PROBLEMS]](/img/37/5c94b9b062a54067a50918f94e61ea.png)
Happy number [fast and slow pointer of ring PROBLEMS]
![[机缘参悟-35]:鬼谷子-飞箝篇-远程连接、远程控制与远程测试之术](/img/08/9ecfd53a04e147022dde3449aec132.png)
[机缘参悟-35]:鬼谷子-飞箝篇-远程连接、远程控制与远程测试之术

AirServer最新Win64位个人版投屏软件

2022年起重机司机(限桥式起重机)考试试题及模拟考试

Turn -- go deep into Lua scripting language, so that you can thoroughly understand the debugging principle

Daily question brushing record (10)
![Jielizhi, production line assembly link [chapter]](/img/5f/9ea7fd3b93df1fd3ecbfc1b669c831.png)
Jielizhi, production line assembly link [chapter]

“35岁,公司老总,月薪2万送外卖“:时代抛弃你,连声再见都没有

Genicam gentl standard ver1.5 (4) Chapter 5 acquisition engine
随机推荐
[kotlin third party] coil koltin collaboration picture loading library coil glide like picture loading third party
Advanced skills of testers: a guide to the application of unit test reports
想请教一下,证券开户选择哪个证券比较好?手机开户是安全么?
思科--WAN 的概念考试外部工具
leetcode - 287. Find duplicates
AAAI22 | 结构标记和交互建模:用于图分类的“SLIM”网络
Programming English vocabulary notebook
Mysql 5.7 实现 rank 排名
What are the benefits of third party acceptance testing? Recommended by professional third-party software testing institutions
dat.GUI
实在RPA:银行数字化,业务流程自动化“一小步”,贷款审核效率“一大步”
[MySQL] index classification
Copy ‘XXXX‘ to effectively final temp variable
Where can the courses purchased by CSDN be accessed
Demo program implementation of QT version Huarui camera
window10安装wsl(一)(WslRegisterDistribution ERROR)
[JUC learning road day 8] condition
Treatment of insufficient space in the root partition of armbain system
Wechat personal small store one click opening assistant applet development
从第三次技术革命看企业应用三大开发趋势