-
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
相关推荐
非 白1 分钟前
【Java分布式】Nacos注册中心吃海鲜的骆驼6 分钟前
服务异步通讯与RabbitMQ羱滒10 分钟前
sql调优之数据库开发规范Forget the Dream38 分钟前
设计模式之责任链模式jonyleek42 分钟前
「JVS更新日志」低代码、企业会议、智能BI、智能排产2.26更新说明计算机小白一个1 小时前
蓝桥杯 Java B 组之最短路径算法(Dijkstra、Floyd-Warshall)曼岛_1 小时前
[密码学实战]Java实现SM4加解密(ecb,cbc)及工具验证Forget the Dream2 小时前
设计模式之代理模式帅的飞起来2 小时前
设计模式--spring中用到的设计模式張葒兵3 小时前
记一次命令行启动springboot项目的问题 java -jar的问题