Circuit Breaker with Resilience4j
Stops calling a failing downstream service temporarily, so one slow/broken dependency can't cascade into a full outage.
@CircuitBreaker(name = "paymentService", fallbackMethod = "fallback")
public String callPaymentService() {
return restTemplate.getForObject("http://payment-service/pay", String.class);
}
public String fallback(Exception ex) {
return "Payment service unavailable, try again later.";
}
- CLOSED — calls pass through normally
- OPEN — calls fail immediately without hitting the downstream service
- HALF_OPEN — a few test calls are allowed through to check if the service recovered