sentinel基于Nacos数据持久化

sentinel基于Nacos数据持久化

1.引入依赖

java 复制代码
<!-- 持久化用到 -->
<dependency>
   <groupId>com.alibaba.csp</groupId>
   <artifactId>sentinel-datasource-nacos</artifactId>
</dependency>

2.yml配置

java 复制代码
server:
 port: 8091
 tomcat:
   max-threads: 10   #最大线程数设置为10,默认200
spring:
 application:
   name: service-order
 datasource:
   driver-class-name: com.mysql.cj.jdbc.Driver
   url: jdbc:mysql://localhost:3306/shop?serverTimezone=Asia/Shanghai
   username: root
   password: 123456
 jpa:
   hibernate:
     ddl-auto: update
 cloud:
   nacos:
     discovery:
       server-addr: localhost:8848
   sentinel:
     transport:
       dashboard: localhost:8080 #提交数据到控制台
       port: 9999  #设置通信端口,任意一个未被使用的端口
     datasource: # 规则持久化
       ds1:
         nacos:
           server-addr: localhost:8848 #nacos地址
           dataId: service-order  #微服务名称
           groupId: DEFAULT_GROUP  #默认分组
           data-type: json #数据格式
           rule-type: flow #流控规则
service-product: #服务提供者名称 负载均衡的策略
 ribbon:
   NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule

3.Nacos添加配置

点击加+号

配置内容

java 复制代码
[
 {
    "resource": "/msg1",
    "limitApp": "default",
    "count": 1,
    "grade": 1,
    "strategy": 0,
    "controlBehavior": 0,
    "clusterMode": false
 }
]

配置内容解释

java 复制代码
resource:资源名称;
limitApp:来源应用;
grade:阈值类型,0表示线程数,1表示QPS;
count:单机阈值;
strategy:流控模式,0表示直接,1表示关联,2表示链路;
controlBehavior:流控效果,0表示快速失败,1表示Warm Up,2表示排队等待;
clusterMode:是否集群。

其实就是Sentinel控制台如下配置:

演示结果

重启服务流控信息存在。

相关推荐
超梦dasgg3 小时前
Sentinel生产环境实战全解
java·微服务·sentinel
Ting-yu5 小时前
SpringCloud快速入门(11)---- Sentinel(异常处理)
java·spring boot·后端·spring·spring cloud·sentinel
Ting-yu5 小时前
SpringCloud快速入门(10)---- Sentinel(应用场景&控制台安装)
spring·spring cloud·sentinel
heimeiyingwang2 天前
【架构实战】服务熔断与限流Sentinel:高可用服务的守护神
架构·sentinel
庞轩px3 天前
第八篇:Spring与微服务——从SpringBoot到SpringCloud的演进
spring boot·spring·微服务·nacos·gateway·sentinel
卷毛的技术笔记6 天前
双十一零点扛过10倍流量洪峰:Sentinel与Redis+Lua的分布式限流深度避坑指南
java·redis·分布式·后端·系统架构·sentinel·lua
chushiyunen7 天前
sentinel限流工具使用
sentinel
Irissgwe7 天前
redis之哨兵(Sentinel)
数据库·redis·sentinel·主从复制·哨兵
phltxy9 天前
微服务高可用实战:Sentinel 熔断与限流从入门到精通
微服务·架构·sentinel
空中海16 天前
第六篇:可靠性篇 — Sentinel 熔断限流与 Seata 分布式事务
分布式·sentinel