当前位置:

微服务springcloud gatway整合sentinel进行流控和nacos持久化

访客 2024-01-05 854 0

1.添加依赖

  • <!--SpringCloudAilibabaSentinel-->
  • <dependency>
  • <groupId>com.alibaba.cloud</groupId>
  • <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
  • </dependency>
  • <!--SpringCloudAilibabaSentinelGateway-->
  • <dependency>
  • <groupId>com.alibaba.cloud</groupId>
  • <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
  • </dependency>
  • <!--sentineldatasourcenacos-->
  • <dependency>
  • <groupId>com.alibaba.csp</groupId>
  • <artifactId>sentinel-datasource-nacos</artifactId>
  • </dependency>
  • 2.配合参数

  • spring:
  • cloud:
  • sentinel:
  • #取消控制台懒加载
  • eager:true
  • transport:
  • #控制台地址
  • dashboard:127.0.0.1:8718
  • #nacos配置持久化
  • datasource:
  • ds1:
  • nacos:
  • server-addr:127.0.0.1:8848
  • dataId:sentinel-gateway
  • groupId:DEFAULT_GROUP
  • data-type:json
  • rule-type:flow
  • 3.nacos中的配置

    dataId:sentinel-gateway

    group:DEFAULT_GROUP

    配置格式:json

  • [
  • {
  • "resource":"demo-auth",
  • "count":500,
  • "grade":1,
  • "limitApp":"default",
  • "strategy":0,
  • "controlBehavior":0
  • },
  • {
  • "resource":"demo-system",
  • "count":1000,
  • "grade":1,
  • "limitApp":"default",
  • "strategy":0,
  • "controlBehavior":0
  • },
  • {
  • "resource":"test-route",
  • "count":1,
  • "grade":1,
  • "limitApp":"default",
  • "strategy":0,
  • "controlBehavior":0
  • }
  • ]
  • 4.dashboard查看流控规则

    在配置中心中修改规则,可以实时应用流控规则,并反映在dashboard页面。

    发表评论

    • 评论列表
    还没有人评论,快来抢沙发吧~