1、创建控制器
@GetMapping("/testHotKey")
@SentinelResource(value = "testHotKey", blockHandler = "deal_testHotKey")
public String testhotkey(
@RequestParam(value = "p1", required = false) String p1,
@RequestParam(value = "p2", required = false) String p2
){
return "-------testHotKey";
}
public String deal_testHotKey(String p1, String p2, BlockException exception){
return "-------deal_testHotKey";
}
2、配置热点key
资源名称即为:@SentinelResource(value = "testHotKey", blockHandler = "deal_testHotKey") 的value
参数索引为从0开始,这里p1参数索引即为0,p2参数索引即为1
当达到热点规则条件后,调用限流方法:deal_testHotKey()
3、测试访问:http://localhost:8401/testHotKey?p1
当1秒内大于或等于2次请求,那么调用限流方法deal_testHotKey()
4、设置参数例外项
以上配置了当p1=5的时候qps为200,即为5时每秒请求上限为200次而不是1次