Spring / Resilience4j Interview questions
How do you apply @CircuitBreaker in a Spring Boot service?
Annotate the method that makes the risky call with @CircuitBreaker(name = "paymentService", fallbackMethod = "paymentFallback"), and Spring AOP wraps it in a proxy that routes the call through the named CircuitBreaker instance.
@CircuitBreaker(name = "paymentService", fallbackMethod = "paymentFallback") public PaymentResponse charge(PaymentRequest req) { return paymentClient.charge(req); } private PaymentResponse paymentFallback(PaymentRequest req, Throwable t) { return PaymentResponse.declined("service unavailable"); }
The name attribute must match an instance configured under resilience4j.circuitbreaker.instances.paymentService in application.yml (or fall back to shared defaults); the fallback method must live in the same class and match the original method's return type plus an added Throwable parameter.
More Related questions...