当前位置:网站首页>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
边栏推荐
- Summary of WLAN related knowledge points
- 自学table au
- 浅谈三点建议为所有已经毕业和终将毕业的同学
- 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?
- State machine in BGP
- When requesting resttemplate, set the request header, request parameters, and request body.
- 栈(线性结构)
- 一口气说出 6 种实现延时消息的方案
- BGP 路由優選規則和通告原則
- Network related knowledge (Hardware Engineer)
猜你喜欢
BGP报文详细解释
Lucene Basics
Redis——Cluster数据分布算法&哈希槽
Learn about various joins in SQL and their differences
Sublime Text 配置php编译环境
Leverage Google cloud infrastructure and landing area to build enterprise level cloud native excellent operation capability
Browser principle mind map
一口气说出 6 种实现延时消息的方案
CUDA中的线程层次
PgSQL学习笔记
随机推荐
Contest3147 - game 38 of 2021 Freshmen's personal training match_ 1: Maximum palindromes
Redis——大Key问题
深入了解JUC并发(二)并发理论
Redis---1. Data structure characteristics and operation
Step by step | help you easily submit Google play data security form
Codeforces Round #797 (Div. 3) A—E
MySQL的10大經典錯誤
Log (common log framework)
锐捷EBGP 配置案例
数据科学【八】:SVD(一)
Browser principle mind map
Is there a really free applet?
CUDA中的Warp matrix functions
介绍两款代码自动生成器,帮助提升工作效率
计算属性普通函数写法 和 set get 写法
底层机制Mvcc
加密压缩文件解密技巧
递归(迷宫问题、8皇后问题)
Classic literature reading -- deformable Detr
VRRP之监视上行链路