Bird
0
0

Which of the following is the correct way to annotate a fallback method using Resilience4j's CircuitBreaker in a Spring Boot microservice?

easy📝 Conceptual Q3 of 15
Microservices - Resilience Patterns
Which of the following is the correct way to annotate a fallback method using Resilience4j's CircuitBreaker in a Spring Boot microservice?
A@CircuitBreaker(name = "myService", fallbackMethod = "handleFallback") public String callService() { return serviceCall(); } public String handleFallback(Throwable t) { return "Fallback response"; }
B@CircuitBreaker(name = "myService") public String callService() { return serviceCall(); } public String handleFallback() { return "Fallback response"; }
C@Fallback(name = "myService", method = "handleFallback") public String callService() { return serviceCall(); }
D@Retry(name = "myService", fallbackMethod = "handleFallback") public String callService() { return serviceCall(); }
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct annotation usage

    Resilience4j's CircuitBreaker supports specifying a fallback method with the fallbackMethod attribute.
  2. Step 2: Check method signatures

    The fallback method must accept the exception parameter (Throwable) to handle errors properly.
  3. Step 3: Analyze options

    @CircuitBreaker(name = "myService", fallbackMethod = "handleFallback") public String callService() { return serviceCall(); } public String handleFallback(Throwable t) { return "Fallback response"; } correctly uses @CircuitBreaker with fallbackMethod and matching method signatures. Options B, C, and D misuse annotations or omit required parameters.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Resilience4j fallback requires fallbackMethod with Throwable param [OK]
Quick Trick: Fallback method needs Throwable parameter [OK]
Common Mistakes:
MISTAKES
  • Omitting fallbackMethod attribute
  • Not including Throwable parameter in fallback
  • Using incorrect annotations like @Fallback or @Retry

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes