Sentinel-Dashboard-1.8持久化Nacos
一、客户端改造
1.引入pom.xml文件依赖
<!-- https://mvnrepository.com/artifact/com.alibaba.csp/sentinel-datasource-nacos -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
<version>2.0.0-alpha</version>
</dependency>
2.配置application.yml文件。
server:
port: 8081
spring:
application:
name: sentinel-nacos-push
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
username: root
password: gj001212
type: com.alibaba.druid.pool.DruidDataSource
cloud:
nacos:
discovery:
server-addr: 192.168.146.1:8839
sentinel:
transport:
dashboard: localhost:7777
port: 8719
eager: true
web-context-unify: false
datasource:
dsl:
nacos:
server-addr: 192.168.146.1:8839
data-id: ${spring.application.name}-flow-rules
group-id: SENTINEL_GROUP
data-type: json
rule-type: flow
flow-rules:
nacos:
server-addr: 192.168.146.1:8839
dataId: ${spring.application.name}-flow-rules
groupId: SENTINEL_GROUP # 注意groupId对应Sentinel Dashboard中的定义
data-type: json
rule-type: flow
degrade-rules:
nacos:
server-addr: 192.168.146.1:8839
dataId: ${spring.application.name}-degrade-rules
groupId: SENTINEL_GROUP
data-type: json
rule-type: degrade
param-flow-rules:
nacos:
server-addr: 192.168.146.1:8839
dataId: ${spring.application.name}-param-flow-rules
groupId: SENTINEL_GROUP
data-type: json
rule-type: param-flow
authority-rules:
nacos:
server-addr: 192.168.146.1:8839
dataId: ${spring.application.name}-authority-rules
groupId: SENTINEL_GROUP
data-type: json
rule-type: authority
system-rules:
nacos:
server-addr: 192.168.146.1:8839
dataId: ${spring.application.name}-system-rules
groupId: SENTINEL_GROUP
data-type: json
rule-type: system
客户端改造完成
二、Sentinel-Dashboard源码改造
1.修改pom.xml中nacos的范围中【test】注释。
2.把test目录下com/alibaba/csp/sentinel/dashboard/rule下的nacos文件夹复制到main相同目录下
3.修改application.properties,增加nacos配置,修改端口
nacos.addr=localhost:8839
4.修改NacosConfig,把nacos信息交给spring容器管理
@Value("${nacos.addr}")
private String addr;
5.修改com/alibaba/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java
@Autowired
@Qualifier("flowRuleDefaultProvider")
private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
@Autowired
@Qualifier("flowRuleDefaultPublisher")
private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;
替换
@Autowired
@Qualifier("flowRuleNacosProvider")
private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
@Autowired
@Qualifier("flowRuleNacosPublisher")
private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;
6.修改webapp/resources/app/scripts/directives/sidebar/sidebar.html
找到如下 html片段 把注释放开
注,这块有两种方式,你可以不放开注释,只需要把留空规则的方法改为
【dashboard.flow】文章来源:https://www.toymoban.com/news/detail-441973.html
<li ui-sref-active="active" ng-if="!entry.isGateway">
<a ui-sref="dashboard.flow({app: entry.app})">
<i class="glyphicon glyphicon-filter"></i> 流控规则</a>
</li>
三、测试
启动nacos和前端项目,sentinel增加流控规则
最后在nacos和sentinel修改文件,测试双向绑定是否成功文章来源地址https://www.toymoban.com/news/detail-441973.html
到了这里,关于Sentinel-Dashboard-1.8持久化Nacos的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!