Sentinel-Dashboard-1.8 Persistence Nacos

Sentinel-Dashboard-1.8 Persistence Nacos

1. Client modification
1.Introduce pom.xml file dependency
<!-- 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. Configure the application.yml file.
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

Client transformation completed

2. Sentinel-Dashboard source code modification

1. Modify the [test] comment in the scope of nacos in pom.xml .
Insert image description here
2. Copy the nacos folder under com/alibaba/csp/sentinel/dashboard/rule in the test directory to the same directory as main
Insert image description here
3. Modify application.properties, add nacos configuration, and modify the port

nacos.addr=localhost:8839

4. Modify NacosConfig and hand over nacos information to spring container management

@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;

replace

@Autowired
@Qualifier("flowRuleNacosProvider")
private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
@Autowired
@Qualifier("flowRuleNacosPublisher")
private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;

6. Modify webapp/resources/app/scripts/directives/sidebar/sidebar.html
to find the following html fragment and release the comments

Note, there are two ways to do this. You don’t need to leave comments, you just need to change the method of leaving blank rules to
[dashboard.flow]

<li ui-sref-active="active" ng-if="!entry.isGateway">
    <a ui-sref="dashboard.flow({app: entry.app})">
        <i class="glyphicon glyphicon-filter"></i>&nbsp;&nbsp;流控规则</a>
</li>
3. Test

Start nacos and front-end projects, add flow control rules
Insert image description here
Insert image description here
in sentinel, and finally modify the files in nacos and sentinel to test whether the two-way binding is successful.

Guess you like

Origin blog.csdn.net/qq_52183856/article/details/130581542