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

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

然后编辑规则:

相关推荐
niaiheni2 小时前
红队实战:记一次Spring Cloud Gateway SpEL表达式注入到哥斯拉内存马(CVE-2022-22947)
web安全·spring cloud·网络安全
daad7772 小时前
记录matlab状态机demo
java·网络·matlab
牡丹雅忻12 小时前
AES 加密模式演进:从 ECB、CBC 到 GCM 的 C# 深度实践
java·开发语言·c#
学者猫头鹰3 小时前
Java 8 核心新特性
java
冰心孤城3 小时前
Excel: xls与xlsx格式转换排坑指南
java·前端·excel
自强的小白3 小时前
maven高级(聚合和私服)以及私服的上传和下载
java·maven
唐青枫3 小时前
Java ReentrantLock 实战详解:比 synchronized 更灵活的可重入锁
java
ShiXZ2134 小时前
Java 8 Stream API 实用技巧详解:从入门到精通
java·开发语言
随风M记忆s4 小时前
GEE&Python-demo:利用Sentinel-监测北京奥林匹克森林公园年NDVI变化(附Python版)
开发语言·python·sentinel
C++、Java和Python的菜鸟5 小时前
第9章 后端Web进阶(AOP)
java·开发语言·前端