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

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

然后编辑规则:

相关推荐
lang201509281 小时前
Sentinel核心机制:Context与EntranceNode解析
网络·sentinel
小小8程序员2 小时前
STL 库(C++ Standard Template Library)全面介绍
java·开发语言·c++
a努力。2 小时前
Redis Java 开发系列#2 数据结构
java·数据结构·redis
a努力。3 小时前
腾讯Java面试被问:String、StringBuffer、StringBuilder区别
java·开发语言·后端·面试·职场和发展·架构
lang201509284 小时前
Alibaba Sentinel核心类CtSph深入分析
sentinel
Vic101014 小时前
解决 Spring Security 在异步线程中用户信息丢失的问题
java·前端·spring
QD_IT伟4 小时前
SpringBoot项目整合Tlog 数据链路的规范加强
java·spring boot·后端
源码获取_wx:Fegn08954 小时前
基于springboot + vue二手交易管理系统
java·vue.js·spring boot·后端·spring·课程设计
Zsh-cs4 小时前
Spring
java·数据库·spring
爬山算法4 小时前
Springboot请求和响应相关注解及使用场景
java·spring boot·后端