docker安装sentinel,sentinel常用操作
docker run --name sentinel -d -p 8858:8858 -d bladex/sentinel-dashboard:1.8.0用户名密码都是 sentinel
·
docker run --name sentinel -d -p 8858:8858 -d bladex/sentinel-dashboard:1.8.0
用户名密码都是 sentinel
windows运行sentinel
java -Dserver.port=8858 -jar sentinel-dashboard-1.8.0.jar
sentinel常用操作
1. qps流控、线程池流控
// blockHandler 流量控制
@RequestMapping("/add")
@SentinelResource(value = "add",blockHandler = "fallbackAdd")
public String add(){
System.out.println("下单成功!");
return "生成订单";
}
public String fallbackAdd(BlockException e){
return "add流量控了";
}
2.BlockException统一异常处理
@Component
public class MyBlockExceptionHandler implements BlockExceptionHandler {
Logger log= LoggerFactory.getLogger(this.getClass());
@Override
public void handle(HttpServletRequest httpServletRequest, HttpServletResponse response, BlockException e) throws Exception {
// getRule() 资源 规则的详细信息
log.info("BlockExceptionHandler BlockException================"+e.getRule());
Result r = null;
if (e instanceof FlowException) {
r = Result.error(100,"接口限流了");
} else if (e instanceof DegradeException) {
r = Result.error(101,"服务降级了");
} else if (e instanceof ParamFlowException) {
r = Result.error(102,"热点参数限流了");
} else if (e instanceof SystemBlockException) {
r = Result.error(103,"触发系统保护规则了");
} else if (e instanceof AuthorityException) {
r = Result.error(104,"授权规则不通过");
}
//返回json数据
response.setStatus(500);
response.setCharacterEncoding("utf-8");
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
new ObjectMapper().writeValue(response.getWriter(), r);
}
}
3. 熔断降级
4. 热点限流
更多推荐
已为社区贡献1条内容
所有评论(0)