Hotspots are frequently accessed data. In many cases, we want to count the topK data with the highest access frequency of a hotspot data and limit it.
E.g:
Merchant ID is a parameter, which counts the most frequently purchased product IDs within a period of time and restricts them.
Hotspot current limiting source code: BlockException class
There is a problem with a method, find the corresponding downgrade method @SentinelResource
test-config:
Test code:
@GetMapping("/testHotKey")
@SentinelResource(value = "testHotKey", blockHandler = "deal_testHostKey")
public String testHotKey(@RequestParam(value = "p1", required = false) String p1,
@RequestParam(value = "p2", required = false) String p2){
return "testHotKey";
}
public String deal_testHostKey(String p1, String p2, BlockException exception){
return "deal_testHotKey";
}
Effect:
If there is no 0th parameter, there is no access and no restrictions at this time
If there is a 0th parameter p1, as long as the QPS exceeds 1 time per second, it will be downgraded immediately.