Java / Micronaut Interview questions
How do you implement retries and circuit breakers in Micronaut?
Micronaut Retry provides both behaviors as declarative annotations built on its AOP mechanism, so no manual try/catch retry loops are needed.
@Client("payments-service") public interface PaymentClient { @Retryable(attempts = "3", delay = "500ms") @CircuitBreaker(reset = "20s") @Get("/charge") Mono<Receipt> charge(ChargeRequest request); }
@Retryable re-invokes the annotated method on failure up to a configured attempt count, with a configurable delay and optional exponential backoff. @CircuitBreaker tracks failure rate and, once a threshold is crossed, "opens" the circuit, short-circuiting further calls immediately for the configured reset period instead of letting them hit a struggling downstream service, then allows a trial call through afterward to check if it has recovered.
Both annotations can be combined, and both are implemented as regular Micronaut AOP interceptors, so they work on any bean method, not just @Client interfaces.
More Related questions...