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: 热点数据";
    }
}

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

然后编辑规则:

相关推荐
zzz_23686 分钟前
【Java实习面试算法冲刺】哈希!
java·算法·面试
带刺的坐椅15 分钟前
ReActAgent 使用指南:构建会思考、能行动的 AI Agent
java·ai·llm·solon·loop·react-agent
漂亮的摩托30 分钟前
如何编写一个SpringBoot项目告警推送的Starter
java·spring boot·后端
盖伦暴打诺手36 分钟前
类比推理知识点
java
ch.ju38 分钟前
Java程序设计(第3版)第四章——类加载
java·开发语言
河阿里39 分钟前
SLF4J深度指南(Java):从原理到 Spring 项目实战
java·开发语言·spring
小沈同学呀42 分钟前
飞书机器人+Spring AI Function Calling实战-扔掉MCP Client让LLM直接操控工具
java·开发语言·functioncalling·spring ai·飞书机器人
EntyIU1 小时前
大文件分片上传完整案例
java
kuro-shiro1 小时前
SpringBoot 启动流程
java·spring boot·后端
吴声子夜歌1 小时前
SQL进阶——EXISTS谓词
java·数据库·sql