增加 spring cloud alibaba sentinel 服务容错

This commit is contained in:
YunaiV
2020-02-14 00:03:52 +08:00
parent 21d475a55c
commit 038a6be4e6
4 changed files with 31 additions and 21 deletions

View File

@@ -122,18 +122,21 @@
# Spring Cloud Alibaba 专栏
## Spring Cloud Alibaba 全家桶
* [《芋道 Spring Cloud Alibaba 注册中心 Nacos 入门》](http://www.iocoder.cn/Spring-Cloud-Alibaba/Nacos-Discovery/?github) 对应 [labx-01](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-01)
* [《芋道 Spring Cloud Netflix 负载均衡 Ribbon 入门》](http://www.iocoder.cn/Spring-Cloud-Netflix/Ribbon/?github) 对应 [labx-02](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-02)
* [《芋道 Spring Cloud 声明式调用 Feign 入门》](http://www.iocoder.cn/Spring-Cloud/Feign/?github) 对应 [labx-03](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-03)
* 《芋道 Spring Cloud Alibaba 服务调用 Dubbo 入门》
* [《芋道 Spring Cloud Alibaba 服务容错 Sentinel 入门》](http://www.iocoder.cn/Spring-Cloud-Alibaba/Sentinel/?github) 对应 [labx-04](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-04)
* 《芋道 Spring Cloud Netflix 服务容错 Hystrix 入门》
* 《芋道 Spring Cloud Alibaba 消息队列 RocketMQ 入门》
* 《芋道 Spring Cloud Alibaba 配置中心 Nacos 入门》
## 推荐搭配食用
* [《芋道 Spring Cloud Netflix 负载均衡 Ribbon 入门》](http://www.iocoder.cn/Spring-Cloud-Netflix/Ribbon/?github) 对应 [labx-02](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-02)
* [《芋道 Spring Cloud 声明式调用 Feign 入门》](http://www.iocoder.cn/Spring-Cloud/Feign/?github) 对应 [labx-03](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-03)
* 《芋道 Spring Cloud 服务网关 Spring Cloud Gateway 入门》
* 《芋道 Spring Cloud Netflix 服务网关 Zuul 入门》
* 《芋道 Spring Cloud 链路追踪 Sleuth 入门》
* 《芋道 Spring Cloud 链路追踪 SkyWalking 入门》
* TODO 监控
# Spring Cloud 专栏
@@ -151,6 +154,22 @@
## 服务容错
* [《芋道 Spring Cloud Alibaba 服务容错 Sentinel 入门》](http://www.iocoder.cn/Spring-Cloud-Alibaba/Sentinel/?github) 对应 [labx-04](https://github.com/YunaiV/SpringBoot-Labs/tree/master/labx-04)
* 《芋道 Spring Cloud Netflix 服务容错 Hystrix 入门》
## API 网关
* 《芋道 Spring Cloud 服务网关 Spring Cloud Gateway 入门》
* 《芋道 Spring Cloud Netflix 服务网关 Zuul 入门》
## 配置中心
* 《芋道 Spring Cloud Alibaba 配置中心 Nacos 入门》
* 《芋道 Spring Cloud 配置中心 Apollo 入门》
## 链路追踪
* 《芋道 Spring Cloud 链路追踪 Sleuth 入门》
* 《芋道 Spring Cloud 链路追踪 SkyWalking 入门》
---------

View File

@@ -10,20 +10,10 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>labx-04-sca-sentinel-demo01-provider</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>6</source>
<target>6</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
<spring.cloud.version>Hoxton.SR1</spring.cloud.version>
<spring.cloud.alibaba.version>2.2.0.RELEASE</spring.cloud.alibaba.version>

View File

@@ -4,7 +4,6 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
//@EnableWebMvc
public class DemoProviderApplication {
public static void main(String[] args) {

View File

@@ -1,6 +1,7 @@
package cn.iocoder.springcloudalibaba.labx04.sentineldemo.provider.web;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -11,9 +12,10 @@ import org.springframework.web.bind.annotation.ResponseBody;
public class GlobalExceptionHandler {
@ResponseBody
@ExceptionHandler(value = BlockException.class)
public String blockExceptionHandler(BlockException blockException) {
return "请求被拦截,拦截类型为 " + blockException.getClass().getSimpleName();
@ExceptionHandler(value = BlockException.class) // 因为这里是示例,所以暂时使用 JSONObject实际项目最终定义一个 CommonResult。
public JSONObject blockExceptionHandler(BlockException blockException) {
return new JSONObject().fluentPut("code", 1024)
.fluentPut("msg", "请求被拦截,拦截类型为 " + blockException.getClass().getSimpleName());
}
}