问题描述

Sentinel Dashboard中添加的规则是存储在内存中的,只要项目一重启规则就丢失了

此处将规则持久化到nacos中,在nacos中添加规则,然后同步到dashboard中;

后面研究如果将dashboard中添加的规则自动添加到nacos中

官网教程地址:https://github.com/alibaba/spring-cloud-alibaba/wiki/Sentinel

实现过程

1.导入依赖包

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>0.9.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
<version>1.5.2</version>
</dependency>
</dependencies>

2.在application.properties中配置sentinel-nacos信息

spring.application.name=mz
server.port=8003 # sentinel dashboard
spring.cloud.sentinel.transport.dashboard=localhost:8080 spring.cloud.sentinel.datasource.ds1.nacos.server-addr=localhost:8848
spring.cloud.sentinel.datasource.ds1.nacos.data-id=mz-sentinel
spring.cloud.sentinel.datasource.ds1.nacos.group-id=DEFAULT_GROUP
spring.cloud.sentinel.datasource.ds1.nacos.data-type=json
spring.cloud.sentinel.datasource.ds1.nacos.rule-type=flow

3.在nacos中添加规则

[
{
"resource": "/hello",
"limitApp": "default",
"grade": 1,
"count": 5,
"strategy": 0,
"controlBehavior": 0,
"clusterMode": false
}
]

4.创建测试类

@RestController
public class Test { @GetMapping("/hello")
public String hello() {
return "hello sentinel";
}
}

访问几次接口之后,就可以在Sentinel Dashboard 中看到在nacos中配置的规则信息了,并且项目服务重启依然存在

本文参考:http://blog.didispace.com/spring-cloud-alibaba-sentinel-2-1/

最新文章

  1. Linux-终端-快捷键
  2. 检测是否IE浏览器
  3. ITSEC TEAM 2013培训公开视频
  4. C# 方法调用的切换器 Update 2015.02.02
  5. 30个最常用css选择器解析(zz)
  6. Vim配置IDE开发环境
  7. c#的多线程
  8. 在redhat6.4下安装 Oracle&#174; Database 11g Release 2
  9. WPF中嵌入Flash(ActiveX)
  10. 破解简单Mifare射频卡密钥杂记
  11. 文件上传[Uploadify]
  12. 【转】被误解的MVC和被神化的MVVM
  13. win8下 msvcr100d.dll文件缺失解决方法
  14. JavaScript+canvas 绘制多边形
  15. .NET作品集:linux下的.net mvc cms
  16. R12中注册客户化应用为多组织应用
  17. leetcode — best-time-to-buy-and-sell-stock-iii
  18. c# 使用http摘要认证
  19. LeetCode-63. 不同路径 II
  20. 好系统重装助手教你如何让win10系统快速开机

热门文章

  1. 把Java代码转成c#可用的dll
  2. linux查看并发连接数
  3. 项目中docker swarm实践
  4. [蓝桥杯2015初赛]方程整数解 unordered_map
  5. centos 6.* 修改时间
  6. python3下scrapy爬虫(第一卷:安装问题)
  7. 如果你的unordered_map头文件报错请看这里
  8. Kubernetes详解
  9. IDEA工具java.io.IOException: Could not find resource SqlMapConfig.xml
  10. Java多态详解