一、环境准备:同上述其他文章
二、Spring Cloud的Gateway服务整合Sentinel
1、pom依赖
<!--sentinel断路器依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
2、bootstrap.yml配置
spring:
cloud:
sentinel:
transport:
port: 7201
dashboard: pfhe.com:7003
3、效果展示
三、Spring Cloud的Gateway服务整合Sentinel,并获取Nacos中的配置。
1、pom依赖
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
2、bootstrap.yml配置
spring:
cloud:
sentinel:
transport:
port: 7201
dashboard: pfhe.com:7003
datasource:
ds-flow:
nacos:
server-addr: pfhe.com:7001
dataId: ${spring.application.name}-sentinel-gateway-flow-rules
groupId: SENTINEL_GROUP
namespace: ${spring.profiles.active}
data-type: json
rule-type: flow
username: nacos
password: nacos
ds-api:
nacos:
server-addr: pfhe.com:7001
dataId: ${spring.application.name}-sentinel-gateway-api-rules
groupId: SENTINEL_GROUP
namespace: ${spring.profiles.active}
data-type: json
rule-type: flow
username: nacos
password: nacos
四、问题总结
1、Sentinel修改网关配置同步到Nacos?
2、网关服务不能开启配置(spring.cloud.sentinel.eager=true,服务启动直接建立心跳连接),否则网关会变成普通服务。
五、拓展
1、Sentinel持久化到nacos中相关文章推荐
【Sentinel、Nacos】Sentinel中读取Nacos中配置(服务和网关)
【Sentinel、Nacos】Sentinel同步修改到Nacos中
【Sentinel、Nacos】Sentinel同步GateWay网关配置到Nacos中