当前位置: 首页 > news >正文

Sentinel整合Gateway

  1. pom引入依赖
    <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>
    
  2. 添加配置
    spring.cloud.sentinel.transport.dashboard=localhost:8858
    spring.cloud.sentinel.transport.port=8749
    spring.cloud.sentinel.filter.enabled=false
    
  3. 硬编码限流规则
    @Configuration
    public class SentinelConfig {@PostConstructpublic 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: 1rule.setGrade(1) ;rule.setCount(1) ;rule.setIntervalSec(1) ;rule.setControlBehavior(1) ;list.add(rule) ;GatewayRuleManager.loadRules(list) ;}
    }
    
  4. 配置网关路由规则
    spring.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
    
  5. 浏览器访问:http://localhost:8080/hello-nacos/hello/index
http://www.lryc.cn/news/167894.html

相关文章:

  • 线性dp,优化,272. 最长公共上升子序列
  • 基于Java+SpringBoot+Vue+uniapp点餐小程序(包含协同过滤算法和会员系统,强烈推荐!)
  • ActiveMQ面试题(二)
  • 解决Oracle SQL语句性能问题——SQL语句改写(in、not in、exists及not exists)
  • 列表对象复制属性到另一个列表对象 从List<Object>另一个List<Object>
  • Python基本情况
  • 【精华】AI Agent:大模型改变世界的“钥匙”
  • CVPR2023 RIFormer, 无需TokenMixer也能达成SOTA性能的极简ViT架构
  • 瑞萨MCU入门教程(非常详细的瑞萨单片机入门教程)
  • 【Java】采用 Tabula 技术对 PDF 文件内表格进行数据提取
  • 完全保密的以太坊交易:Aztec网络的隐私架构
  • 初识Java 9-1 内部类
  • 合宙Air724UG LuatOS-Air LVGL API控件-屏幕横屏竖屏切换(Rotation)
  • 在Unity中,Instantiate函数用于在场景中创建一个新的游戏对象实例
  • 解决 tesserocr报错 Failed to init API, possibly an invalid tessdata path : ./
  • 使用Python CV2融合人脸到新图片--优化版
  • Python分享之对象的属性
  • 编程参考 - std::exchange和std::swap的区别
  • Sentinel整合RestTemplate
  • 微前端学习(下)
  • Android Splash实现
  • FPGA projet : VGA
  • JDK8 升级至JDK19
  • Python3.10 IDLE更换主题
  • C# OpenVino Yolov8 Pose 姿态识别
  • 北邮22级信通院数电:Verilog-FPGA(1)实验一“跑通第一个例程” 过程中遇到的常见问题与解决方案汇总(持续更新中)
  • CSS - 鼠标移入整行高亮显示,适用于会员套餐各参数对比页面(display: table,div 转表格形式)
  • 无涯教程-JavaScript - ATAN2函数
  • Tomcat 下部署 jFinal
  • 【Spatial-Temporal Action Localization(二)】论文阅读2017年