一 说明
1.1 说明
本案例是在
https://blog.csdn.net/u011066470/article/details/129637207
此篇博文基础上进行改良操作。
本案例实现就是:使用sentinel的流控等规则对请求接口进行限流规则的配置,验证。
1.2 架构图
二 操作案例
2.1 pom配置
<!--SpringCloud ailibaba sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
2.2 sentinel的配置
配置篇
spring:
application:
name: alibaba-nacos-consumer6000
cloud:
nacos:
discovery:
server-addr: localhost:8848
sentinel:
transport:
#配置Sentinel dashboard地址
dashboard: localhost:8080
#默认8719端口,假如被占用会自动从8719开始依次+1扫描,直至找到未被占用的端口
port: 8719
代码篇
2.3 启动nacos,sentinel并配置流控规则
1.启动nacos和sentinel
2.配置流控和降级规则
流控
降级
2.4 测试
1.正常访问
快速访问,触发限流规则:如下图
2.参数异常访问
快速访问,触发降级规则
3.访问数据不存在
快速访问,触发降级规则
2.5 结论
结论: blockHandler只负责sentinel控制台配置违规