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

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

然后编辑规则:

相关推荐
St_rive4 小时前
Page Object设计模式
java·开发语言·设计模式
风流 少年4 小时前
Spring AI 2.0:SSE
java·人工智能·spring
凤山老林5 小时前
精细化流量治理:Spring Boot 动态特性开关与灰度发布体系
java·spring boot·后端
Aphelios3807 小时前
一次锁内网络IO引发的Tomcat线程池“饿死”事故
java·开发语言·spring boot·elasticsearch·tomcat·网络io阻塞·线程池耗尽
不可求~7 小时前
C++ std::string_view 不是字符串:从悬空引用到安全用法
java·开发语言·c++
Lam Tang7 小时前
APS 系列文章10
java·代理模式
考虑考虑8 小时前
Excel导入时产生特殊字符处理
java·后端·java ee
Scabbards_8 小时前
面试Leetcode - Heap 堆
java·leetcode·面试
程序员清风9 小时前
专业再升级!程序员专属显示器明基RD280UG上手实测!
java·后端·面试
我命由我1234510 小时前
RxJava - 冷数据流与热数据流
android·java·java-ee·android studio·rxjava·android-studio·android runtime