https://github.com/bootcamptoprod/spring-boot-resilience4j-rate-limiter
A simple app highlighting how we can implement rate limiter using Resilience4j in Spring Boot
https://github.com/bootcamptoprod/spring-boot-resilience4j-rate-limiter
java java-17 rate-limit rate-limiter rate-limiter-api rate-limiting resilience resilience4j resiliency resilient resilient-sy rest rest-api spring spring-boot spring-boot-3
Last synced: 3 months ago
JSON representation
A simple app highlighting how we can implement rate limiter using Resilience4j in Spring Boot
- Host: GitHub
- URL: https://github.com/bootcamptoprod/spring-boot-resilience4j-rate-limiter
- Owner: BootcampToProd
- Created: 2023-07-01T16:18:58.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-02T12:37:48.000Z (almost 2 years ago)
- Last Synced: 2025-01-07T14:46:19.690Z (5 months ago)
- Topics: java, java-17, rate-limit, rate-limiter, rate-limiter-api, rate-limiting, resilience, resilience4j, resiliency, resilient, resilient-sy, rest, rest-api, spring, spring-boot, spring-boot-3
- Language: Java
- Homepage: https://bootcamptoprod.com/resilience4j-rate-limiter
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Mastering Resilience4j Rate Limiter with Spring Boot: A Practical Guide
For complete understanding of Resilience4j Rate Limiter module and how we can use it inside the Spring Boot application you can checkout our blog.
**Blog Link:** [Mastering Resilience4j Rate Limiter with Spring Boot: A Practical Guide](https://bootcamptoprod.com/resilience4j-rate-limiter)
## spring-boot-resilience4j-rate-limiter
A simple app highlighting how we can implement rate limiter using Resilience4j in Spring Boot.## App Overview
This is a simple app wherein we are fetching the movie details based on the movie id. The movie details are fetched from external service that is called using the Spring Rest Template. For simplicity, we have created a mock controller which acts as a external service for returning the movie details.## Rate Limiter Scenarios
We have created a single controller endpoint which accepts movie id as path parameter and query parameter rateLimitType which accepts predefined set of values to mimic the different rate limiter examples.### Acceptable Values
#### For Path Parameter - Movie Id
a. **1** or **2** - Mock controller returns valid movie information
b. **3** - Mock controller returns HTTP status code 404
c. **4** or **any other numeric value** - Mock controller returns null which leads to MovieNotFound Exception#### For Query Parameter - rateLimitType
Different rate limiter instances are defined inside the application.yml. To mimic different rate limiting scenarios use:
a. **simple-rate-limit:** simpleRateLimit rate limiter instance will be triggered
b. **rate-limit-with-event-details:** rateLimiterEventsExample rate limiter instance will be triggered.
c. **rate-limit-with-fallback:** simpleRateLimit rate limiter instance will be triggered and fallback method logic will be executed in this case.
d. **rate-limit-with-custom-config:** customRateLimiterConfig rate limiter instance defined in RateLimiterConfiguration class will be triggered.## cURL Commands
Check the application logs in order to get the better understanding of different rate limiter scenarios.### 1. Simple Rate Limit
```
curl 'http://localhost:8080/movies/3?rateLimitType=simple-rate-limit'
```### 2. Rate Limit with Fallback
```
curl 'http://localhost:8080/movies/1?rateLimitType=rate-limit-with-fallback'
```### 3. Rate Limit with Custom Configuration
```
curl 'http://localhost:8080/movies/1?rateLimitType=rate-limit-with-custom-config'
```### 4. Rate Limit with Event Details
```
curl 'http://localhost:8080/movies/1?rateLimitType=rate-limit-with-event-details'
```