规则持久化(Sentinel)

规则持久化

基于Nacos配置中心实现推送

引入依赖

XML 复制代码
<dependency>
    <groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-datasource-nacos</artifactId>
</dependency>

流控配置文件

java 复制代码
[
    {
        "resource":"/order/flow",
        "controlBehavior":0,
        "count":10.0,
        "grade":1,
        "limitApp":"default",
        "strategy":0
    }
]

流控文件相关配置

java 复制代码
server:
  port: 8061
spring:
  application:
    name: order-sentinel
  cloud:
    sentinel:
      transport:
        dashboard: 127.0.0.1:8080
      web-context-unify: false # 默认请求链路进行收敛
      datasource:
        flow-rule:
          nacos:
            server-addr: 127.0.0.1:8847
            username: nacos
            password: nacos
            data-id: order-sentinel-flow-rule
            group-id: SENTINEL_GROUP
            rule-type: flow

重启服务、看效果

  • 流控规则 已经存在了

访问效果

弊端

  • Sentinel 上修改阈值后 无法同步到 nacos
  • 需手动修改nacos中的配置保持 和 Sentinel 中的一致
相关推荐
llwszx2 分钟前
Spring中DelayQueue深度解析:从原理到实战(附结构图解析)
java·后端·spring·delayqueue·延迟任务
述雾学java17 分钟前
Spring Cloud Feign 整合 Sentinel 实现服务降级与熔断保护
java·spring cloud·sentinel
保持学习ing17 分钟前
苍穹外卖day3--公共字段填充+新增菜品
java·阿里云·实战·springboot·前后端·外卖项目·阿里云文件存储
77qqqiqi36 分钟前
正则表达式
java·后端·正则表达式
厦门德仔1 小时前
【WPF】WPF(样式)
android·java·wpf
大春儿的试验田1 小时前
高并发收藏功能设计:Redis异步同步与定时补偿机制详解
java·数据库·redis·学习·缓存
Gappsong8741 小时前
【Linux学习】Linux安装并配置Redis
java·linux·运维·网络安全
hqxstudying1 小时前
Redis为什么是单线程
java·redis
RainbowSea1 小时前
NVM 切换 Node 版本工具的超详细安装说明
java·前端
逆风局?1 小时前
Maven高级——分模块设计与开发
java·maven