Persist Sentinel Rules to Nacos: Step-by-Step Configuration Guide

Learn how to persist Alibaba Sentinel flow control rules in Nacos by adding the necessary Maven dependency, configuring the datasource in application.yml, setting up rule data in the Nacos console, and verifying the rules via the Sentinel dashboard, with code snippets and screenshots.

Ops Development Stories
Ops Development Stories
Ops Development Stories
Persist Sentinel Rules to Nacos: Step-by-Step Configuration Guide

Persist Sentinel Rules to Nacos

Sentinel rule configurations disappear after a service restart. By storing these rules in a configuration center such as Zookeeper, Apollo, or Nacos, the rules can be shared across restarts and multiple nodes.

Add Nacos Storage Dependency

Include the following Maven dependency to declare that Sentinel will use Nacos as the rule data store:

<dependency>
  <groupId>com.alibaba.csp</groupId>
  <artifactId>sentinel-datasource-nacos</artifactId>
</dependency>

Add YML Configuration

If you use Sentinel's standalone datasource feature, declare the datasource information in application.yml:

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: flow

Configure Rules in Nacos

In the Nacos console, add a new configuration with the correct dataId and groupId . The data should follow the JSON format, for example:

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

View Configuration in Sentinel

Start the service and open the Sentinel dashboard. Under the "Flow Control" menu you can see the rules defined in the configuration center.

Summary

The above steps complete the persistence of Sentinel rules to Nacos. Note that after modifying rules in the Sentinel console, the changes are not automatically synchronized back to Nacos; manual source code changes or a push‑mode synchronization are required.

For more details, refer to the official Sentinel documentation: Sentinel Wiki .

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

NacosSentinelSpring CloudRule Persistence
Ops Development Stories
Written by

Ops Development Stories

Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.