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 分钟前
Java底层探秘进阶:JIT汇编逐行拆解!Java方法栈帧与C语言深度对标
java·c语言·汇编
老华带你飞8 分钟前
智能菜谱推荐|基于java + vue智能菜谱推荐系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
小钟不想敲代码25 分钟前
Python(三)
java·python·servlet
Qiu的博客28 分钟前
Spring Boot 全局异常处理策略设计(一):异常不只是 try-catch
java·spring
Han.miracle32 分钟前
Java集合核心:ArrayList与LinkedList深度解析
java·开发语言
篱笆院的狗34 分钟前
Group by很慢,如何定位?如何优化?
java·数据库
期待のcode1 小时前
Java的反射
java·开发语言
2201_757830871 小时前
AOP入门程序
java·开发语言
雨中飘荡的记忆1 小时前
MyBatis反射模块详解
java·mybatis