这里使用:
springboot 2.3.2.RELEASE
springcloud Hoxton.SR8
spring alibaba cluod 2.2.5.RELEASE
sentinel-datasource-nacos 1.8.0
sentinel 1.8.5
注解配置、控制台配置都无法解决配置丢失问题,通过Nacos配置中心解决该问题
下载源码:https://github.com/alibaba/Sentinel/archive/refs/tags/1.8.5.zip
@Autowired
@Qualifier("flowRuleNacosProvider")
private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
@Autowired
@Qualifier("flowRuleNacosPublisher")
private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;
<li ui-sref-active="active" ng-if="entry.appType==0">
<a ui-sref="dashboard.flowV1({app: entry.app})">
<i class="glyphicon glyphicon-filter"></i> 流控规则 V1</a>
</li>
<li ui-sref-active="active" ng-if="!entry.isGateway">
<a ui-sref="dashboard.flow({app: entry.app})">
<i class="glyphicon glyphicon-filter"></i> 流控规则 Nacos</a>
</li>
<!--sentinel持久化 -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
<!-- nacos服务注册与发现 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- nacos配置 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
server:
port: 8806
spring:
application:
name: sentinel-user-nacos-push #微服务名称
#配置nacos注册中心地址
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
sentinel:
transport:
# 添加sentinel的控制台地址
dashboard: 127.0.0.1:8080
# 指定应用与Sentinel控制台交互的端口,应用本地会起一个该端口占用的HttpServer
#port: 8719
clientIp: localhost
datasource:
# ds1: #名称自定义,唯一
# nacos:
# server-addr: 127.0.0.1:8848
# dataId: ${spring.application.name}-flow-rules
# groupId: SENTINEL_GROUP
# data-type: json
# rule-type: flow
flow-rules:
nacos:
namespace: dddddd
server-addr: 127.0.0.1:8848
dataId: ${spring.application.name}-flow-rules
groupId: SENTINEL_GROUP# 注意groupId对应Sentinel Dashboard中的定义
data-type: json
rule-type: flow
degrade-rules:
nacos:
server-addr: 127.0.0.1:8848
dataId: ${spring.application.name}-degrade-rules
groupId: SENTINEL_GROUP
data-type: json
rule-type: degrade
param-flow-rules:
nacos:
server-addr: 127.0.0.1:8848
dataId: ${spring.application.name}-param-flow-rules
groupId: SENTINEL_GROUP
data-type: json
rule-type: param-flow
authority-rules:
nacos:
server-addr: 127.0.0.1:8848
dataId: ${spring.application.name}-authority-rules
groupId: SENTINEL_GROUP
data-type: json
rule-type: authority
system-rules:
nacos:
server-addr: 127.0.0.1:8848
dataId: ${spring.application.name}-system-rules
groupId: SENTINEL_GROUP
data-type: json
rule-type: system
main:
allow-bean-definition-overriding: true
#暴露actuator端点 http://localhost:8800/actuator/sentinel
management:
endpoints:
web:
exposure:
include: '*'
#feign:
# sentinel:
# enabled: true #开启sentinel对feign的支持 默认false
[
{
"clusterConfig":{
"acquireRefuseStrategy":0,
"clientOfflineTime":2000,
"fallbackToLocalWhenFail":true,
"resourceTimeout":2000,
"resourceTimeoutStrategy":0,
"sampleCount":10,
"strategy":0,
"thresholdType":0,
"windowIntervalMs":1000
},
"clusterMode":false,
"controlBehavior":0,
"count":1,
"grade":1,
"limitApp":"default",
"maxQueueingTimeMs":500,
"resource":"/test1",
"strategy":0,
"warmUpPeriodSec":10
}
]
注意:“limitApp”:“default”,这个参数默认为default