-
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
相关推荐
剑挑星河月41 分钟前
94.二叉树的中序遍历2301_801184751 小时前
docker 工作老前端的功夫1 小时前
【Java从入门到入土】47:构建工具:Maven与Gradle的战争aaPIXa6221 小时前
C++模板元编程:在编译期完成计算,实现零运行时开销夜郎king1 小时前
RuoYi-Vue3 企业级后台快速落地实战指南二宝哥2 小时前
创建Gradle多模块SpringBoot项目AI人工智能+电脑小能手2 小时前
【大白话说Java面试题 第156题】【06_Spring篇】第16题:Spring 用到了哪些设计模式?曹牧2 小时前
XML 解析过程中遇到 `org.xml.sax.SAXParseException要开心吖ZSH3 小时前
处方物流信息同步优化:从 36 秒到亚秒级的踩坑记录Wang's Blog3 小时前
JavaWeb快速入门: MyBatis入门与实战