Try resilience4j
- Mark Kendall
- 5 days ago
- 2 min read
📦 Recommended Downloadable Project
• resilience4j-spring-boot-demo:
A curated Spring Boot demo showcasing CircuitBreaker, Retry, Bulkhead, TimeLimiter, and RateLimiter patterns in practice using Resilience4j .
⸻
✅ How to Get and Run It
1. Clone the repository:
cd resilience4j-spring-boot-demo
2. Build & run:
• Using Gradle:
./gradlew bootRun
• Or import into your IDE and run the Application.java entry point directly .
3. Hit sample endpoints to trigger resilience mechanisms:
• Circuit breaker
• Retry with fallback
• Bulkhead and time limiter isolation
• Rate limiting
4. Inspect configurations in application.yml or application.properties:
• Tune parameters like slidingWindowSize, failureRateThreshold, maxAttempts, timeoutDuration, etc. .
⸻
🛠️ How to Adapt for Your Book Catalog API
You can integrate this resilience demo into your Book API by following these steps:
• Add dependencies:
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot3</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
• Annotate service methods with resilience annotations:
@CircuitBreaker(name = "bookService", fallbackMethod = "fallbackGetAllBooks")
@Retry(name = "bookService", fallbackMethod = "fallbackGetAllBooks")
public List<BookResponse> getAllBooks() { … }
public List<BookResponse> fallbackGetAllBooks(Throwable ex) {
// return cached data or default list
return Collections.emptyList();
}
Optionally add @Bulkhead, @TimeLimiter, @RateLimiter as needed .
• Configure resilience settings in your application.yml:
resilience4j:
circuitbreaker:
instances:
bookService:
slidingWindowSize: 5
failureRateThreshold: 50
waitDurationInOpenState: 5s
retry:
instances:
bookService:
maxAttempts: 3
waitDuration: 1s
bulkhead:
instances:
bookService:
maxConcurrentCalls: 10
timelimiter:
instances:
bookService:
timeoutDuration: 2s
ratelimiter:
instances:
bookService:
limitForPeriod: 20
limitRefreshPeriod: 1s
⸻
🌟 Summary
• The resilience4j-spring-boot-demo repo is a ready-to-run, downloadable Spring Boot project integrating resilience patterns across various examples.
• You can easily adapt it to your existing Book Catalog API to add retry/fallback, circuit breaking, bulkheading, timeout protection, and rate limiting as needed.
• The demo includes Actuator metrics and optional monitoring integrations (e.g. Prometheus/Grafana) for real-time visibility .
⸻
Next Steps Suggestions:
a. Integrate this demo’s resilience layer directly into your Book API (adding annotations + config)
b. Add unit and integration tests with JUnit and Mockito to simulate timeouts, failures, and ensure fallback methods work correctly
Comments