1.在gateway服务模块中添加gateway整合sentinel的依赖
<!--sentinel整合gateway的依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>
<!--sentinel的依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
2. 在application.yml配置文件中添加sentinel控制台的配置
sentinel: #sentinel的配置
transport:
dashboard: localhost:8080 #配置sentinel dashboard地址
port: 8719 #默认端口8719
3. 编写gateway配置类,自定义限流配置
package com.mc.tutor.config;
import com.alibaba.csp.sentinel.adapter.gateway.common.SentinelGatewayConstants;
import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition;
import com.alibaba.csp.sentinel.adapter.gateway.common.api.Api

本文介绍了如何在Java微服务环境中,通过Spring Cloud Gateway结合Sentinel来实现服务的流控、熔断和降级操作。首先,在Gateway服务模块添加相关依赖;接着,配置application.yml以连接Sentinel控制台;最后,编写自定义配置类以定义限流规则。
最低0.47元/天 解锁文章
1087

被折叠的 条评论
为什么被折叠?



