Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to annotate a method with a circuit breaker using Resilience4j.
Spring Boot
@CircuitBreaker(name = "[1]") public String callExternalService() { // method implementation }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic name that does not match configuration
Leaving the name blank
Using an invalid identifier
✗ Incorrect
The circuit breaker name should match the configured backend service name, here 'backendService'.
2fill in blank
mediumComplete the code to configure the circuit breaker failure rate threshold in application.yml.
Spring Boot
resilience4j.circuitbreaker.instances.backendService.failureRateThreshold: [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting failure rate threshold too high or too low
Using invalid numeric values
Forgetting to specify the correct instance name
✗ Incorrect
The failure rate threshold is commonly set to 50%, meaning the circuit breaker opens if failures exceed 50%.
3fill in blank
hardFix the error in the annotation to enable fallback method on circuit breaker failure.
Spring Boot
@CircuitBreaker(name = "backendService", fallbackMethod = "[1]") public String callExternalService() { // method implementation }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic or incorrect fallback method name
Not defining the fallback method at all
Mismatch in method parameters
✗ Incorrect
The fallback method name must match the actual method defined to handle failures, here 'handleFallback'.
4fill in blank
hardFill both blanks to configure the wait duration and sliding window size for the circuit breaker.
Spring Boot
resilience4j.circuitbreaker.instances.backendService.waitDurationInOpenState: [1] resilience4j.circuitbreaker.instances.backendService.slidingWindowSize: [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing units between time and count
Setting too small or too large values
Using invalid formats like missing 's' for seconds
✗ Incorrect
The wait duration is set to 60 seconds and sliding window size to 50 calls for balanced circuit breaker behavior.
5fill in blank
hardFill all three blanks to complete the method signature for a fallback method with exception parameter.
Spring Boot
public String [1](Throwable [2]) { return "Fallback response due to " + [3].getMessage(); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatch between fallback method name and annotation
Using different parameter names inconsistently
Not including Throwable parameter
✗ Incorrect
The fallback method is named 'handleFallback' and uses 'ex' as the Throwable parameter to get the error message.