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

二、配置热点参数限制规则
SpringCloud: sentinel热点参数限制_第1张图片
然后编辑规则:
SpringCloud: sentinel热点参数限制_第2张图片

你可能感兴趣的:(SpringCloud,spring,cloud,sentinel,java)