Circuit Breaker
- Return a
fallback responseif a service is down or slow -
Example: return a default set of products if the catalog service is down
-
Circuit Breaker Framework:
Resilience4j(former hystrix) - Spring AOP and Spring Actuator are required
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot2</artifactId>
</dependency>
Circuit Breaker States
Closed: normally process all the requestsHalf-Closed: normally process a percentage of the requestsOpen: directly return the fallback response