返回介绍

6.4 Nacos 集成 Sentinel 配置

发布于 2025-04-21 20:58:45 字数 1334 浏览 0 评论 0 收藏

Sentinel 的配置规则都是存储到内存中,并没有持久化,因此需要提供一个持久化的解决方案。通过和 Nacos 整合可以将 Sentinel 配置规则推送到 Nacos 上进行存储。具体步骤如下:

(1)在应用中添加依赖包 sentinel-datasource-nacos,具体代码如下:

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

(2)在配置文件中添加 Nacos 属性配置,具体代码如下:

spring:
  cloud:
    sentinel:
      datasource:
        flow:
          nacos:
            server-addr: 127.0.0.1:8848
            dataId: test-flow-rules
            groupId: test
            rule-type: flow
        degrade:
          nacos:
            server-addr: 127.0.0.1:8848
            dataId: test-degrade-rules
            groupId: test
            rule-type: degrade
        system:
          nacos:
            server-addr: 127.0.0.1:8848
            dataId: test-system-rules
            groupId: test
            rule-type: system
        authority:
          nacos:
            server-addr: 127.0.0.1:8848
            dataId: test-authority-rules
            groupId: test
            rule-type: authority
        param-flow:
          nacos:
            server-addr: 127.0.0.1:8848
            dataId: test-param-flow-rules
            groupId: test
            rule-type: param-flow

完成以上配置后,重新启动 Nacos 管理后台即可看到配置的 Sentinel 规则数据信息。

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。