4. Consider this incorrect Resilience4j usage in Spring Boot:
@CircuitBreaker(name = "serviceB", fallback = "fallbackMethod")
public String fetchData() {
// call external API
}
What is the main issue with this code?
medium
A. The method fetchData must return void
B. Circuit breaker name cannot be "serviceB"
C. The fallback method name should be specified with fallbackMethod, not fallback
D. The annotation @CircuitBreaker cannot be used on public methods
Solution
Step 1: Check annotation attribute names
The correct attribute for fallback method name is fallbackMethod, not fallback.
Step 2: Validate other conditions
Method return type and visibility are valid; circuit breaker name can be any string.
Final Answer:
The fallback method name should be specified with fallbackMethod, not fallback -> Option C
Quick Check:
Correct fallback attribute = fallbackMethod [OK]
Hint: Use fallbackMethod attribute for fallback name [OK]
Common Mistakes:
Using 'fallback' instead of 'fallbackMethod'
Thinking method must be void
Assuming circuit breaker name is restricted
5. You want to design a Spring Boot microservice that calls an unstable external payment API. Using Resilience4j circuit breaker, which approach best ensures system stability and graceful degradation?
hard
A. Apply @CircuitBreaker with a fallback method returning a cached payment status
B. Remove circuit breaker and rely on retries only
C. Use @CircuitBreaker without fallback to fail fast
D. Disable circuit breaker and increase thread pool size
Solution
Step 1: Understand system stability needs
Using a circuit breaker prevents repeated calls to the unstable API, avoiding overload.
Step 2: Importance of fallback for graceful degradation
A fallback method returning cached or default data keeps the system responsive during failures.
Step 3: Evaluate other options
Retries alone can worsen overload; no fallback causes failures; increasing threads doesn't solve API instability.
Final Answer:
Apply @CircuitBreaker with a fallback method returning a cached payment status -> Option A