-
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
相关推荐
2601_961133284 分钟前
盘立方软件指标文华期货公式下载蜗牛互联网11 分钟前
长任务多Agent共享文件系统的Manifest交接模式Sirens.33 分钟前
Java并发锁详解:六类锁策略与 synchronized 底层原理sunshine22 girl1 小时前
Java学习五 面向对象高级5 内部类1用户1305180712153 小时前
JDBC学习DAY2:从Statement到PreparedStatement蛋蛋的就会顺顺的3 小时前
hot100——矩阵周杰偷奶茶3 小时前
【Java】数组的定义和使用(附管理系统实战案例)橙子圆1234 小时前
JUC之集合类不安全谢亮_vipxieliang5 小时前
Stream API 不是银弹:常见坑与性能建议源码宝5 小时前
Web‑PACS 云影像源码|Java+Vue3 医院影像管理系统完整方案