当前位置:网站首页>Sentinel implements the persistence of pull pattern rules
Sentinel implements the persistence of pull pattern rules
2022-07-24 10:25:00 【Liu Chu, Ge Nian】
List of articles
introduction
sentinel All rules of are stored in memory by default , After restart, all rules will be lost . In production environment , We must ensure the persistence of these rules , Avoid losing .
Rule management mode
Whether rules can persist , It depends on the rule management mode ,sentinel Three rule management modes are supported :
- Primitive mode :Sentinel Default mode , Save rules in memory , Restarting the service will lose .
- pull Pattern
- push Pattern
pull Pattern
pull Pattern : The console pushes the configured rules to Sentinel client , The client will save the configuration rules in a local file or database . In the future, we will regularly query local files or databases , Update local rules .

push Pattern
push Pattern : The console pushes the configuration rules to the remote configuration center , for example Nacos.Sentinel Client listening Nacos, Get the push message of configuration change , Complete local configuration update .

Sentinel pull Pattern rule persistence
It's used here 1.8.1 , You need to change the source code yourself , I wonder whether the subsequent versions support automatic configuration
One 、 Modify service
Modify the microservice project you want to introduce , Let it listen Nacos Medium sentinel Rule configuration .
The specific steps are as follows :
1. Introduce dependencies
stay order-service Introduction in sentinel monitor nacos Dependence :
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
2. To configure nacos Address
stay order-service Medium application.yml File configuration nacos Address and listening configuration information :
spring:
cloud:
sentinel:
datasource:
flow:
nacos:
server-addr: localhost:8848 # nacos Address
dataId: orderservice-flow-rules
groupId: SENTINEL_GROUP
rule-type: flow # It can also be :degrade、authority、param-flow
Two 、 modify sentinel-dashboard Source code
SentinelDashboard Not supported by default nacos The persistence of , Need to modify the source code .
Download the source code from the official website :
use IDEA Open the project :
The project directory is as follows , Download dependency package ( It could take a long time , I used Alibaba cloud to give me more than ten minutes )

2. modify nacos rely on
stay sentinel-dashboard Source code pom In file ,nacos The default dependency is scope yes test, Can only be used during testing , Here we need to remove :

take sentinel-datasource-nacos Rely on the scope Get rid of :
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
3. add to nacos Support
stay sentinel-dashboard Of test It's a bag , A pair of nacos Support for , We need to copy it to main Next .

4. modify nacos Address
then , You also need to modify the... In the test code NacosConfig class :

Modify the nacos Address , Let it read application.properties Configuration in :

stay sentinel-dashboard Of application.properties Add nacos Address configuration :
nacos.addr=localhost:8848
5. To configure nacos data source
in addition , It needs to be revised com.alibaba.csp.sentinel.dashboard.controller.v2 Under bag FlowControllerV2 class :

Let's add Nacos Data source in effect :
Modify as follows

@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. Modify the front page
Next , Also modify the front page , Add a support nacos Menu for .
modify src/main/webapp/resources/app/scripts/directives/sidebar/ In the catalog sidebar.html file :

Open this part of the comment :

Modify the text :

7. recompile 、 Packaging project
function IDEA Medium maven plug-in unit , Compile and package the modified Sentinel-Dashboard:

8. start-up
The start-up method is the same as the official :
java -jar sentinel-dashboard.jar
If you want to modify nacos Address , Need to add parameters :
java -jar -Dnacos.addr=localhost:8848 sentinel-dashboard.jar
边栏推荐
- 图像处理:RGB565转RGB888
- [carving master learning programming] Arduino hands-on (59) - RS232 to TTL serial port module
- Golang migrate is easy to use
- ffmpeg花屏解决(修改源码,丢弃不完整帧)
- Chapter V Modification implementation (impl) class
- OSPF含特殊区域实验,MGRE构建和重发布
- Analysis of distributed lock redistribution principle
- [STM32 learning] (8) stm32f1 general timer configuration
- NiO knowledge points
- [correcting Hongming] what? I forgot to take the "math required course"!
猜你喜欢
![[STM32 learning] (12) STM32 realizes LCD1602 simple static reality](/img/78/954ebaae0cce5d9387e7032fa85e60.png)
[STM32 learning] (12) STM32 realizes LCD1602 simple static reality

常量指针、指针常量
![[STM32 learning] (13) STM32 realizes ultrasonic ranging (hc-sr04)](/img/6e/b7cf7a8e3296e29d61a0626e3793ea.png)
[STM32 learning] (13) STM32 realizes ultrasonic ranging (hc-sr04)

Sentinel 三种流控模式

Zoj1137+ operation 1 -- May 28, 2022

Create a vertical seekbar from scratch

Golang migrate is easy to use

Query about operating system security patch information

When the hot tea is out of stock, what does the new tea drink rely on to continue its life?

Can the "self-help master" who has survived the economic crisis twice continue to laugh this time?
随机推荐
OSPF includes special area experiments, mGRE construction and re release
Dynamic planning: robbing families and houses
Homologous policy solutions
The heads of the five major international institutions called for urgent action to deal with the global food security crisis
Figure model 2-2022-5-13
常量指针、指针常量
Create a vertical seekbar from scratch
Balance between management / business and technology
Activity exception lifecycle
Differential restraint system -- 1 and 2 -- May 27, 2022
New:Bryntum Grid 5.1.0 Crack
Mysql InnoDB下联合索引的索引数量?
Add a love power logo to your website
Value on the object Z rotation synchronization panel in unity
What did zoneawareloadbalancer of ribbon and its parent class do?
【LeeCode】获取2个字符串的最长公共子串
[recommendation system] the classic technical architecture of the data flow of the recommendation system + the most complete evolution map of the top 10 deep learning CTR models of Microsoft, Alibaba,
Record AP and map calculation examples
NIO知识点
Onpropertychange event "suggestions collection"