Cloud Native 4 min read

Persist Sentinel Flow Rules in Nacos: Step‑by‑Step Configuration Guide

This tutorial explains how to store Sentinel flow‑control rules in Nacos so that they survive service restarts, covering Maven dependencies, YAML datasource configuration, Nacos rule publishing, and verification through the Sentinel console, while noting synchronization limitations.

Ops Development Stories
Ops Development Stories
Ops Development Stories
Persist Sentinel Flow Rules in Nacos: Step‑by‑Step Configuration Guide

Sentinel rule configurations disappear after a service restart; to keep them persistent you can store the rules in a configuration center such as Zookeeper, Apollo, or Nacos.

In our project we already use Nacos as both service registry and configuration center, and we can also use it as the storage repository for Sentinel rule data.

Add Nacos Storage Dependency

Include the following Maven dependency to declare that Sentinel will use Nacos for rule persistence.

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

Add YML Configuration

If you enable Sentinel’s independent datasource feature, declare the datasource settings in your application.yml file as follows.

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

Add Nacos Configuration

In the Nacos console, create a new configuration entry for the Sentinel rules and publish it. Be careful to use the correct dataId and groupId, otherwise the rules cannot be found.

Nacos rule configuration screenshot
Nacos rule configuration screenshot

Example JSON template for a flow rule:

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

Verify Sentinel Configuration

Start the service and open the Sentinel dashboard; under the "Flow Control" menu you can view the rules that were defined in Nacos.

Sentinel console showing flow rules
Sentinel console showing flow rules

Summary

We have completed all steps to persist Sentinel rules to Nacos. Note that after modifying rules in the Sentinel console, the changes are not automatically synchronized back to Nacos; to achieve this you must modify the Sentinel console source code to push updates to Nacos.

For more details, refer to the official Sentinel documentation: https://github.com/alibaba/Sentinel/wiki/Sentinel-%E6%8E%A7%E5%88%B6%E5%8F%B0%EF%BC%88%E9%9B%86%E7%BE%A4%E6%B5%81%E6%8E%A7%E7%AE%A1%E7%90%86%EF%BC%89#%E8%A7%84%E5%88%99%E9%85%8D%E7%BD%AE

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-cloudconfiguration-managementflow-control
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.