sentinel限流授权规则持久化
1. sentinel规则模式有三种
(1)原始模式,默认模式把规则存放在内存中,服务重启后规则消失。
(2)pull模式,定时轮询模式,数据可能不一致。
(3)push模式,利用nacos配置中心实现配置监听和更新。
2.实现push模式
(1)引入jar
<!--sentinel规则持久化-->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
(2)SentinelDashboard默认不支持nacos的持久化,需要修改源码,详见sentinel持久化修改。
(3)微服务配置
spring: nacos: sentinel: datasource: flow: nacos: serverAddr: localhost:80 dataId: orderservice-flow-rules groupId: SENTINEL-GROUP ruleType: flow
(4)修改后的sentinel源码jar包启动
java -jar -Dnacos-addr=localhost:8848 sentinel-dashboard.jar
(5)刷新sentinel页面,发送请求,清除缓存,会出现流控规则-NACOS

浙公网安备 33010602011771号