SpringCloud: sentinel热点参数限制

一、定义controller

复制代码
package cn.edu.tju.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HotParamController {
    @RequestMapping("/getHotParam/{id}")
    @SentinelResource(value = "getHotParam", blockHandler = "myBlockHandler")
    public String getHotParam(@PathVariable String id){
        return "get: " + id;
    }

    public String myBlockHandler(@PathVariable String id, BlockException ex){
        return "get: 热点数据";
    }
}

二、配置热点参数限制规则

然后编辑规则:

相关推荐
北城笑笑2 分钟前
Vue 115 ,上篇:给智能体装上计费表,行知订阅次数额度与每日额度双规则设计( 需求分析与方案设计,Vue3 + RuoYi 3.9.2 + 主子账号 )
java·前端·javascript·数据库·vue.js·后端·vue
saltwater本尊4 分钟前
给运行态JVM进行端到端测试
java
stormsha13 分钟前
`Connection is not available, request timed out after 30000ms`:不是数据库慢,是池子空了
java·后端·mysql
不要试图纠正别人19 分钟前
结构化并发不撒谎,代价是把线程泄漏换成请求挂死
java·后端
豌豆学姐19 分钟前
图片数字人API接入教程:通过人物图片和音频实现AI口型同步视频生成
java·前端·javascript
J.YA39 分钟前
Java I/O 总结
java·开发语言
爬也要爬着前进43 分钟前
tomcat日志logrotate
java·tomcat
长不大的杨瑞杰1 小时前
Spring Boot 4 + Java 25 虚拟线程实战:配置、压测、限流与线上排障
java·spring boot·后端·spring·软件工程
Forget the Dream2 小时前
Spring AI 2.0 系列(四):Starter 与 OpenAI-compatible:一个不绑死厂商的模型环境
java·人工智能·spring·springai