Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Nacos to store Sentinel rule information

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to use Nacos to store Sentinel rules information, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Sentinel rule configuration, once we restart the service, all the rules will disappear. We can store these rule configurations through Zookeeper, Applo, Nacos and other configuration centers, so that the configuration data can be shared when the service is restarted or when multiple nodes are started.

In the previous project, we used Nacos as the service registry and service configuration center, and we can also use Nacos as the configuration data repository of Sentinel to provide us with the persistence of Sentinel configuration data. As shown in the following figure

Increase Nacos storage dependency

The following dependencies need to be introduced independently to declare that sentinel's rule data is stored in nacos.

Com.alibaba.csp sentinel-datasource-nacos add YML configuration

If we use the stand-alone data source feature of Sentinel, we need to declare the data source configuration information in the yaml file.

Spring: application: name: stock-service profiles: active: dev cloud: sentinel: transport: port: 8719 dashboard: localhost:8080 enabled: true datasource: ds: nacos: dataId: ${spring.application.name}-flow-rules groupId: DEFAULT_GROUP data-type: json rule-type: flowNacos add configuration

In the Nacas configuration center, we need to add the rule configuration and publish it. Note that dataId and groupId must make no mistake, otherwise the data configuration will not be found, as shown in the following figure:

Data template

[{"resource": "abc", "controlBehavior": 0, "count": 20.0, "grade": 1, "limitApp": "default", "strategy": 0}]

Finally, when we start the service and the Sentinel console, we can see the flow control information we defined in the configuration center under the flow control information menu.

Sentinel View configuration

Thank you for reading this article carefully. I hope the article "how to use Nacos to store Sentinel rule information" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report