-
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
相关推荐
Ahtacca17 分钟前
Redis 五大常用数据类型详解及 Java 客户端(RedisTemplate)操作实战Coder_Boy_34 分钟前
基于SpringAI企业级智能教学考试平台视频辅助学习模块全业务闭环方案廋到被风吹走39 分钟前
【Spring】Spring Cache 深度解析计算机毕设VX:Fegn08951 小时前
计算机毕业设计|基于springboot + vue个人博客系统(源码+数据库+文档)2501_946675641 小时前
Flutter与OpenHarmony打卡轮播图组件独自破碎E1 小时前
Spring Boot 3.x和2.x版本相比有哪些区别与改进?坚持学习前端日记1 小时前
个人运营小网站的最佳策略幽络源小助理1 小时前
SpringBoot+Vue美食网站系统源码 | Java餐饮项目免费下载 – 幽络源k***92161 小时前
C++:继承Coder_Boy_1 小时前
基于SpringAI企业级智能教学考试平台考试模块全业务闭环方案