了解spring-cloud-alibaba-sentinel

spring-cloud-alibaba-sentinel.jar是sentinel在springboot下的包装

META-INF下 spring.factories说明了相关的自动加载类,

SentinelWebAutoConfiguration

SentinelFeignAutoConfiguration

添加对Feign的限流包装,主要通过Feign-> 实现invocationHandlerFactory的create方法,通过jdk的InvocationHandler的invoke方法中添加Sphu.entry的sentinel限流

SentinelWebFluxAuoConfiguration

在spring-gateway(应用了springwebFlux框架)中添加限流

SentinelAutoConfiguration

对配置的加载(支持db等),声明SentinelBeanPostProcessor通过MergedBeanDefinitionPostProcessor实现对SentinelRestTemplate注解限流配置的使用,beanDefinitionPostProcessor判断是否为RestTemplate对象且添加了Sentinel注解,after方法中添加RestTemplate的interceptor拦截SentinelProtectInterceptor。

spring-configuration-metada.json对配置属性作了对应的注解,初次引入框架可以详细查看metadata的内容,即便不熟悉,也能较快的应用到项目中。

jar简洁清晰,便于了解springboot的加载及如何模块化编程,通过不同的方式实现对各种场景下的限流加载。

经验分享 程序员 微信小程序 职场和发展