-
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
相关推荐
iwS2o90XT1 分钟前
Java多线程编程:Thread与Runnable的并发控制wangchunting10 分钟前
spring-boot-starter-validation字段数据校验阿Y加油吧11 分钟前
堆 / 优先队列专题二刷笔记:前 K 个高频元素 & 数据流的中位数凯尔萨厮14 分钟前
创建Springboot空项目梵得儿SHI18 分钟前
SpringCloud 进阶拓展:分布式事务终极解决方案 Seata AT/TCC 模式全栈实战(含生产级避坑指南)深邃-35 分钟前
【Web安全】-Kali,Linux配置(2):Java环境配置,Python环境配置,Conda使用,PIP配置使用,SSH远程登录jjjava2.036 分钟前
Java多线程编程:从入门到实战Seven9737 分钟前
Tomcat 线程池的设计与实现:StandardThreadExecutor爱笑的Sunday37 分钟前
Linux Java前后端项目 企业级0-1完整部署手册