当前位置:网站首页>Sentinel rules persist to Nacos
Sentinel rules persist to Nacos
2022-07-02 06:26:00 【dotaer-df】
- Pull mode : The client takes the initiative to poll a rule management center regularly for pull rules , The center of the rule can be RDBMS、 file , Even VCS etc. . The way to do this is simple , The disadvantage is that you can't get changes in time ;
- Push mode : The rule center pushes , The client listens for changes all the time by registering a listener , For example, use Nacos、Zookeeper Wait for the configuration center . This way has better real-time and consistency guarantee .
In this paper Nacos That is, push pattern persistence rules , This way of interaction is cut off Sentinel Client and Sentinel Dashboard The connection of . Its interaction mode is like this : When Sentinel Dashboard After rule change , It will be pushed to Nacos, Again Nacos Push to client , As shown in the figure below :
This method needs to be modified in two places :
1、 modify Sentinel Dashboard Source code ( Actually Dashboard It's connected to nacos, We just need to replace the default implementation )
2、Sentinel Client access Nacos
modify Sentinel Dashboard Source code
1、 download Sentinel Dashboard project
https://github.com/alibaba/Sentinel/tree/master/sentinel-dashboard
2、 take test The contents are about Nacos copy to com.alibaba.csp.sentinel.dashboard.rule
among FlowRuleNacosProvider From Nacos Middle pull rule ,FlowRuleNacosPublisher Will send to Nacos Push rules , This is a Dashboard The implementation provided for us
3、 Then replace FlowControllerV2 Class DynamicRuleProvider by Nacos The implementation of the
4、 Then the front-end page should also be changed to call v2 The interface of , Call by default /v1/flow
sidebar.html(resources/app/scripts/directives/sidebar) page
Control rule routing fromdashboard.flowV1
Change todashboard.flow
app.js(resources/dist/js/app.js) take app/scripts/controllers/flow_v1.js
Replace with app/scripts/controllers/flow_v2.js
Sentinel Dashboard Modified to complete !!
Sentinel Client access Nacos
2、Sentinel in the light of Nacos The results showed that there was no significant difference between the two groups , The bottom layer can adopt Nacos As a rule configuration data source . Just add the following dependencies when using :
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
<version>1.8.0</version>
</dependency>
Complete dependence :
<!-- rely on web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- sentinel springboot-starter -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<version>2021.1</version>
</dependency>
<!-- sentinel Core dependence -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
<version>1.8.0</version>
</dependency>
<!--sentinel Persistence -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
<version>1.8.0</version>
</dependency>
Yml To configure
server:
port: 8081
spring:
application:
name: sentinel
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
sentinel:
transport:
dashboard: 127.0.0.1:8080 # Appoint sentinel dashboard web Address
datasource:
ds1: # Name customization , only
nacos:
server-addr: 127.0.0.1:8848
dataId: ${spring.application.name}-flow-rules
groupId: SENTINEL_GROUP
data-type: json
rule-type: flow
among dataId and groupId Want to be with Sentinel Dashboard in FlowRuleNacosPublisher the push The consistency of , The default values are as follows , So we can also set the default value
Then start one by one Sentinel Dashboard and Sentinel The client can , from Dashboard The rules modified in will be immediately pushed to Nacos, from Nacos Added rules Dashboard Can also sense , And even if the client or Dashboard restart , Data can also be obtained from Nacos Read it out , Persistence is achieved
边栏推荐
- LeetCode 90. Subset II
- Does the assignment of Boolean types such as tag attribute disabled selected checked not take effect?
- LeetCode 40. Combined sum II
- 代码技巧——Controller参数注解@RequestParam
- 线性dp(拆分篇)
- DeprecationWarning: .ix is deprecated. Please use.loc for label based indexing or.iloc for positi
- Let every developer use machine learning technology
- 自学table au
- Redis——大Key问题
- Find the highest value of the current element Z-index of the page
猜你喜欢
Hydration failed because the initial UI does not match what was rendered on the server.问题原因之一
Data science [viii]: SVD (I)
Contest3147 - game 38 of 2021 Freshmen's personal training match_ A: chicken
Redis——Cluster数据分布算法&哈希槽
Linked list (linear structure)
深入了解JUC并发(一)什么是JUC
Learn about various joins in SQL and their differences
Monitoring uplink of VRRP
Introduce two automatic code generators to help improve work efficiency
PgSQL学习笔记
随机推荐
华为MindSpore开源实习机试题
代码技巧——Controller参数注解@RequestParam
日期时间API详解
利用传统方法(N-gram,HMM等)、神经网络方法(CNN,LSTM等)和预训练方法(Bert等)的中文分词任务实现
【每日一题】—华为机试01
In depth understanding of JUC concurrency (I) what is JUC
IPv6 experiment and summary
Linear DP (split)
广告业务Bug复盘总结
eslint配置代码自动格式化
LeetCode 40. Combined sum II
BGP 路由優選規則和通告原則
Redis---1. Data structure characteristics and operation
Introduce two automatic code generators to help improve work efficiency
Top 10 classic MySQL errors
sudo提权
BGP中的状态机
MySql索引
稀疏数组(非线性结构)
LeetCode 40. 组合总和 II