当前位置:网站首页>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) pageControl rule routing fromdashboard.flowV1Change 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: flowamong 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 78. subset
- Browser principle mind map
- It is said that Kwai will pay for the Tiktok super fast version of the video? How can you miss this opportunity to collect wool?
- 浅谈三点建议为所有已经毕业和终将毕业的同学
- Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish
- LeetCode 83. Delete duplicate elements in the sorting linked list
- Cglib agent - Code enhancement test
- Introduce two automatic code generators to help improve work efficiency
- The Chinese word segmentation task is realized by using traditional methods (n-gram, HMM, etc.), neural network methods (CNN, LSTM, etc.) and pre training methods (Bert, etc.)
- Zhuanzhuanben - LAN construction - Notes
猜你喜欢

深入学习JVM底层(三):垃圾回收器与内存分配策略

Sentinel 阿里开源流量防护组件

Singleton mode compilation

找到页面当前元素z-index最高的数值

构建学习tensorflow

Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish

Ruijie ebgp configuration case

Learn about various joins in SQL and their differences

Redis——大Key問題

LeetCode 90. 子集 II
随机推荐
Contest3147 - game 38 of 2021 Freshmen's personal training match_ A: chicken
Data science [viii]: SVD (I)
Sentinel 阿里开源流量防护组件
浅谈三点建议为所有已经毕业和终将毕业的同学
加密压缩文件解密技巧
Hydration failed because the initial UI does not match what was rendered on the server.问题原因之一
深入学习JVM底层(四):类文件结构
Redis---1. Data structure characteristics and operation
Redis——缓存击穿、穿透、雪崩
Network related knowledge (Hardware Engineer)
日期时间API详解
最新CUDA环境配置(Win10 + CUDA 11.6 + VS2019)
Top 10 classic MySQL errors
VRRP之监视上行链路
LeetCode 83. Delete duplicate elements in the sorting linked list
广告业务Bug复盘总结
Browser principle mind map
锐捷EBGP 配置案例
Let every developer use machine learning technology
构建学习tensorflow