码迷,mamicode.com
首页 > 编程语言 > 详细

springcloud 集成Sentinel 1.8持久化到nacos

时间:2021-01-21 10:31:19      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:framework   loading   info   规则   sys   work   dash   rgba   名称   

1、客户端pom引入

 <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
            <version>2.2.4.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>com.alibaba</groupId>
                    <artifactId>fastjson</artifactId>
                </exclusion>
            </exclusions> 
  </dependency>
 <dependency>
    <groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-datasource-nacos</artifactId>
    <version>1.8.0</version>
</dependency>

2、yaml文件修改

spring:
  cloud: 
    sentinel:
      port: 8719
      eager: true
      transport: 
     # sentinel客户端地址 dashboard:
127.0.0.1:8080 datasource: flow: nacos:
#nacos地址 server
-addr: ${spring.cloud.nacos.discovery.server-addr}
       #nacos dataId 详细看 sentinel 客户端添加到nacos下的保持一致 dataId: ${spring.application.name}
-flow-rules
#nacos namespace 详细看 sentinel 客户端添加到nacos下的保持一致 namespace: ${spring.cloud.nacos.discovery.namespace}
       #nacos namespace  详细看 sentinel 客户端添加到nacos下的保持一致        groupId: SENTINEL_GROUP
#data-type: json # 规则类型,取值见: # org.springframework.cloud.alibaba.sentinel.datasource.RuleType rule-type: flow #熔断降级 名称随意 degrade: nacos: server-addr: ${spring.cloud.nacos.discovery.server-addr} dataId: ${spring.application.name}-degrade-rules namespace: ${spring.cloud.nacos.discovery.namespace} groupId: SENTINEL_GROUP rule-type: degrade #系统规则 名称随意 system: nacos: server-addr: ${spring.cloud.nacos.discovery.server-addr} dataId: ${spring.application.name}-system-rules namespace: ${spring.cloud.nacos.discovery.namespace} groupId: SENTINEL_GROUP rule-type: system #授权规则 名称随意 authority: nacos: server-addr: ${spring.cloud.nacos.discovery.server-addr} dataId: ${spring.application.name}-authority-rules namespace: ${spring.cloud.nacos.discovery.namespace} groupId: SENTINEL_GROUP rule-type: authority #参数规则 名称随意 param-flow: nacos: server-addr: ${spring.cloud.nacos.discovery.server-addr} dataId: ${spring.application.name}-param-flow-rules namespace: ${spring.cloud.nacos.discovery.namespace} groupId: SENTINEL_GROUP rule-type: param-flow

 

3、测试
   在sentinel 客户端增加 接口的 熔断规则后 访问该接口 出现如下场景 即是成功

技术图片

 

springcloud 集成Sentinel 1.8持久化到nacos

标签:framework   loading   info   规则   sys   work   dash   rgba   名称   

原文地址:https://www.cnblogs.com/ldmy/p/14302332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!