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

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

然后编辑规则:

相关推荐
硅的褶皱3 小时前
对比分析LinkedBlockingQueue和SynchronousQueue
java·并发编程
MoFe13 小时前
【.net core】天地图坐标转换为高德地图坐标(WGS84 坐标转 GCJ02 坐标)
java·前端·.netcore
季鸢4 小时前
Java设计模式之观察者模式详解
java·观察者模式·设计模式
Fanxt_Ja4 小时前
【JVM】三色标记法原理
java·开发语言·jvm·算法
Mr Aokey5 小时前
Spring MVC参数绑定终极手册:单&多参/对象/集合/JSON/文件上传精讲
java·后端·spring
14L5 小时前
互联网大厂Java面试:从Spring Cloud到Kafka的技术考察
spring boot·redis·spring cloud·kafka·jwt·oauth2·java面试
小马爱记录5 小时前
sentinel规则持久化
java·spring cloud·sentinel
长勺6 小时前
Spring中@Primary注解的作用与使用
java·后端·spring
紫乾20146 小时前
idea json生成实体类
java·json·intellij-idea
wh_xia_jun6 小时前
在 Spring Boot 中使用 JSP
java·前端·spring boot