官方文档地址

本文springcloud2021版本为例

springcloudgateway文档地址: https://spring.io/projects/springcloudgateway#overview

springcloudcircuitbreaker文档地址: https://spring.io/projects/springcloudcircuitbreaker

两者关系

首先springcloudgateway集成了断路器springcloudcircuitbreaker(官网截图
在这里插入图片描述
再来看看断路器 springcloudcircuitbreaker
在这里插入图片描述
从文档看circuitbreaker目前版本(3.0.3),支持Resilience4J和Spring Retry

首先circuitbreaker框架是对各种断路器的封装底层还是依赖各种三方的断路器实现之前旧版本网关gateway支持netflixhystrix做断路器,但是在新版本中已经不再支持;

如在旧版本gateway里可以直接引入如下,既可以使用hystrix网关断路器:

      <dependency&gt;
          <groupId&gt;org.springframework.cloud</groupId&gt;
          <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
      </dependency>

但是后面gateway弃用了对netflixhystrix的支持。

在新版本gateway里可以使用如下引用circuitbreaker作为gateway的断路器

      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
      </dependency>

所以旧版本spring-cloud-starternetflixhystrixspring-cloud-starter-circuitbreaker-xxxxxx 是同一级别框架,但是circuitbreaker更加抽象了一层,底层支持Resilience4J和Spring Retry

其实在旧版本的circuitbreaker中也有对hystrix的支持(因为circuitbreaker是一个抽象框架,类似SLF4J框架兼容Log4j,logback、Java Util Logging),以下是旧版本的circuitbreaker文档(现在找不到了)

在这里插入图片描述
但是由于hystrix已经停止更新,后面也被circuitbreaker弃用了。(这一段比较饶脑)

所以从目前看,hystrix被抛弃了两次!!!

集成自动装配

结论:只要我们网关项目引入circuitbreaker相关starter则gateway会将断路器自动集成例如

  <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
  </dependency>
原理

todo~~

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注