-
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
相关推荐
头发还在的女程序员17 小时前
医院陪诊管理系统怎么选择?——2026 年选型避坑与架构参考CodeStats17 小时前
【Spring事务】Spring事务注解 @Transactional 完整体系:从 MySQL 隔离级别到 MyBatis 原理详解我命由我1234518 小时前
Android 开发问题:为 PDFView 设置一个带有黑色边框的背景 drawable,但边框没有生效都叫我大帅哥20 小时前
从Python到Java:为什么企业级Agent最终会选择Java?wanderist.20 小时前
Lambda表达式在算法竞赛中的应用zhougl99621 小时前
Gateway 和 Nginx 路由区别腻害兔1 天前
【若依项目-产品经理视角】RuoYi-Vue-Pro 源码拆解:IM 即时通讯模块,一个被低估的「全功能聊天系统」心念枕惊1 天前
.NET CORE 授权进阶-角色、策略与动态权限实现沉迷学习 日益消瘦1 天前
10-Gateway API景同学1 天前
把 AI 用到线上运维:可行、有效,前提是喂足信息——一次 Full GC 排障实录