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

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

然后编辑规则:

相关推荐
chuan.bai2 小时前
Java RAG 实战(第 11 篇):RAG 知识工作台网页
java·开发语言·人工智能
0x534 小时前
网站通信(一)
java
Terra.K4 小时前
Java异常学习[特殊字符]
java·开发语言·学习
葡萄城技术团队6 小时前
InfluxDB 2\.x 深度解析:核心架构、Flux 函数与制造业落地指南(三)
java·开发语言·架构
Super 含6 小时前
Android 启动优化(五):线程、GC 与 IO 为什么会拖慢启动?
java·服务器·数据库
counting money6 小时前
Java IO流详解:从InputStream到文件操作实战
java·开发语言·python
程序员小八7777 小时前
上海百度B端java后端日常实习一面
java·开发语言
mldong8 小时前
零依赖的秘密:8 大 SPI 设计
java·架构
Diligently_10 小时前
Anolis 系统更新与密码设置&磁盘扩容
java·后端·spring