目录
热点参数流控规则是一种更细粒度的流控规则,它允许将规则具体到参数上。
示例热点规则的使用:
1、编写测试接口代码
package cn.jack.controller;
import cn.jack.service.impl.OrderServiceImpl3;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Slf4j
public class OrderController3 {
@RequestMapping("/order/message3")
@SentinelResource("message3") // 注意这里必须使用@SentinelResource注解标注,否则热点规则不生效
public String message3(String name, Integer age) {
return "message3 name=" + name + ", age=" + age;
}
}
2、配置热点规则
3、分别用两个参数访问,会发现只对第一个参数限流了
4、补充
还可以为热点规则增加参数例外项(热点规则编辑页面才有此选项)。例如,参数name的值如果为jack,qps阈值达到6才限流: