-
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
相关推荐
阿维的博客日记3 小时前
Hippo4j 线程池监控平台部署手册C+++Python5 小时前
详细介绍一下Java泛型的通配符JosieBook6 小时前
【数据库】时序预测能力的分级进化:TimechoAI如何让每一类用户都能精准预见未来一生了无挂7 小时前
Java处理JSON技巧教学(从基础到高阶实战全覆盖)李白的天不白7 小时前
使用 SmartAdmin 进行前后端开发swordbob8 小时前
Spring 单例 Bean 是线程安全的吗?2601_951643778 小时前
Python第一,Java跌出前三,C语言杀回来了IT 行者10 小时前
GitHub Spec Kit 实战(五):/speckit.tasks 怎么拆——Spec Kit 五部曲收官(Charon)10 小时前
【C++ 面试高频基础:指针、引用、const、static、new/delete 总结】Yeats_Liao11 小时前
Feed流系统设计(三):数据模型与存储设计,从表结构到Redis收件箱