@RestController
public class SentinelResourceController {
@GetMapping("/resource")
@SentinelResource(value = "resource",blockHandler = "handleException")
public String resource(){
return "SentinelResourceController invoke resource success";
}
public String handleException(BlockException e){
return "SentinelResourceController invoke handleException";
}
}
然后启动项目,在浏览器输入地址,然后在sentinel的控制台就可以看到了
刷新频繁会出现
public class ZrsBlockHandler {
public static String handler1Exception(BlockException exception){
return "ZrsBlockHandler invoke handler【1】Exception";
}
public static String handler2Exception(BlockException exception){
return "ZrsBlockHandler invoke handler【2】Exception";
}
}
@RestController
public class SentinelResourceController {
@GetMapping("/resource")
@SentinelResource(value = "resource",blockHandler = "handleException")
public String resource(){
return "SentinelResourceController invoke resource success";
}
public String handleException(BlockException e){
return "SentinelResourceController invoke handleException";
}
@GetMapping("/handler1")
@SentinelResource(value = "handler1Exception",blockHandlerClass = ZrsBlockHandler.class,
blockHandler = "handler1Exception")
public String handler1(){
return "SentinelResourceController invoke resource success";
}
@GetMapping("/handler2")
@SentinelResource(value = "handler2Exception",blockHandlerClass = ZrsBlockHandler.class,
blockHandler = "handler2Exception")
public String handler2(){
return "SentinelResourceController invoke resource success";
}
}
http://localhost:8005/handler1
http://localhost:8005/handler2
频繁访问
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/weixin_43296313/article/details/121029765
内容来源于网络,如有侵权,请联系作者删除!