在生产环境中,我们可以使用拉模式或者推模式来实现规则的持久化,但是都需要一些配置,这里介绍阿里云的sentinel托管平台AHAS(Application High Availability Service)来实现规则的持久化。
一、开通AHAS
二、进入AHAS控制台
三、操作演示
1、添加依赖
<!--AHAS依赖-->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>spring-boot-starter-ahas-sentinel-client</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<exclusions>
<exclusion>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-transport-simple-http</artifactId>
</exclusion>
</exclusions>
</dependency>
注意:对于
spring-cloud-starter-alibaba-sentinel
依赖我们需要排除sentinel-transport-simple-http
(与原生sentinel控制台通信需要的)依赖。
2、application.yml
ahas.namespace: default
project.name: content-center
ahas.license: 许可证
3、重启应用,访问资源
如果页面没有显示相应的应用,参考如下解决方案。
再次重启应用,我们依然可以看到之前配置的规则依然生效。