-
pom引入依赖
text<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId> </dependency>
-
添加配置
propertiesspring.cloud.sentinel.transport.dashboard=localhost:8858 spring.cloud.sentinel.transport.port=8749 spring.cloud.sentinel.filter.enabled=false
-
硬编码限流规则
java@Configuration public class SentinelConfig { @PostConstruct public void init(){ this.initCustomizeRule(); } private void initCustomizeRule(){ Set<GatewayFlowRule> list = new HashSet<>() ; GatewayFlowRule rule = new GatewayFlowRule("hello-nacos-client") ; rule.setResourceMode(SentinelGatewayConstants.RESOURCE_MODE_ROUTE_ID) ; // qps: 1 rule.setGrade(1) ; rule.setCount(1) ; rule.setIntervalSec(1) ; rule.setControlBehavior(1) ; list.add(rule) ; GatewayRuleManager.loadRules(list) ; } }
-
配置网关路由规则
propertiesspring.cloud.gateway.enabled=true spring.cloud.gateway.discovery.locator.lower-case-service-id=true spring.cloud.gateway.routes[0].id=hello-nacos-client spring.cloud.gateway.routes[0].uri=lb://hello-nacos-client spring.cloud.gateway.routes[0].predicates[0]=Path=/hello-nacos/** spring.cloud.gateway.routes[0].filters[0]=StripPrefix=1
Sentinel整合Gateway
yicj2023-09-17 16:32
相关推荐
风象南5 分钟前
SpringBoot 控制器的动态注册与卸载我是一只代码狗31 分钟前
springboot中使用线程池hello早上好44 分钟前
JDK 代理原理PanZonghui1 小时前
Centos项目部署之Java安装与配置沉着的码农1 小时前
【设计模式】基于责任链模式的参数校验Mr_Xuhhh2 小时前
信号与槽的总结虚!!!看代码2 小时前
【Sentinel学习】Fireworkitte2 小时前
Redis 源码 tar 包安装 Redis 哨兵模式(Sentinel)何苏三月2 小时前
SpringCloud系列 - Sentinel 服务保护(四)纳兰青华2 小时前
bean注入的过程中,Property of ‘java.util.ArrayList‘ type cannot be injected by ‘List‘