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

SpringCloud: sentinel链路限流

一、配置文件要增加

      spring.cloud.sentinel.webContextUnify: false

二、在要限流的业务方法上使用@SentinelResource注解

package cn.edu.tju.service;import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.stereotype.Service;@Service
public class UserService {@SentinelResource(value = "getUser", blockHandler = "myBlockingHandler")public String getUser(){return " a user...";}public String myBlockingHandler(BlockException ex){System.out.println("链路限流");return "链路限流啦";}
}

三、定义接口调用业务方法

package cn.edu.tju.controller;import cn.edu.tju.service.UserService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class UserController {@Autowiredprivate UserService userService;@RequestMapping("/getUser1")public String getUser1(){return userService.getUser();}@RequestMapping("/getUser2")public String getUser2(){return userService.getUser();}
}

四、在sentinel控制台设置链路限流规则:
在这里插入图片描述
五、启动应用,快速刷新接口/getUser1
在这里插入图片描述

http://www.lryc.cn/news/197786.html

相关文章:

  • UML 中的关系
  • ChatGPT技术或加剧钓鱼邮件攻击
  • 哨兵1号后向散射系数土壤水分反演
  • day3:Node.js 基础知识
  • 【RDMA】librdmacm库和连接建立过程
  • 如何使用Python抓取PDF文件并自动下载到本地
  • 人脸写真FaceChain的简单部署记录(一)
  • linux虚机新增加磁盘后在系统中查不到
  • js中隐式类型转换与toPrimitive
  • 家政系统预约小程序具备哪些功能?
  • 【LeetCode】46. 全排列
  • 宏电股份RedCap产品亮相迪拜华为MBBF,并参与RedCap全球商用阶段性成果发布
  • Harris图像角点检测
  • 互联网Java工程师面试题·Java 总结篇·第七弹
  • UVa658 It’s not a Bug, it’s a Feature!(Dijkstra)
  • Object 类常用方法
  • chromium 52 chrome 各个版本发布功能列表(58-84)
  • python web开发(四): Bootstrap
  • 【EI会议征稿】2024年遥感技术与测量测绘国际学术会议(RSTSM 2024)
  • 灵感:VUE2实现权限按钮控制
  • 【2023最新版】Python全栈知识点总结
  • 推荐系统离线评估方法和评估指标,以及在推荐服务器内部实现A/B测试和解决A/B测试资源紧张的方法。还介绍了如何在TensorFlow中进行模型离线评估实践。
  • day1:Node.js 简介
  • ESP RainMaker 客户案例 #1|Halonix
  • 【Linux】adduser命令使用
  • 中文连续视觉语音识别挑战赛
  • (ubuntu) 安装JDK
  • 工程管理系统源码之全面+高效的工程项目管理软件
  • 网络安全常见问题隐患及其应对措施
  • 《机器学习分类器 二》——朴素的贝叶斯算法,项目实践,算法实践。