如果你只是想简简单单的做个熔断,那你可找对地方了,本文章只讲解sentinel的熔断降级,不讲解sentinel的限流,限流可查看我的另外一篇文章
建议使用注解方式,这样对代码没有侵入性,对于新老项目都是很友好的
1.导入sentinle依赖和切面依赖
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-annotation-aspectj</artifactId>
<version>1.8.1</version>
</dependency>
2.编写接口
@GetMapping("testSentinel")
@SentinelResource(value = RESOURCE_NAME,fallback = "queryUserByUserNameFallBack")
public R<String> testSentinel() {
int i = 1 / 0;
return R.success("Hello Sentinel");
}
2.1接口讲解
3.熔断降级方法讲解
4.quick start over,祝大家越来越牛