Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rapter1990/ratelimiter
Spring Boot Rate Limiter with Redis (Spring Boot, Java 21, JUnit, Integration Test, Github Actions, Test Container, Docker, Redis)
https://github.com/rapter1990/ratelimiter
cicd docker docker-compose github-actions integration-test java java21 junit lombok maven postman redis spring-boot testcontainer
Last synced: about 4 hours ago
JSON representation
Spring Boot Rate Limiter with Redis (Spring Boot, Java 21, JUnit, Integration Test, Github Actions, Test Container, Docker, Redis)
- Host: GitHub
- URL: https://github.com/rapter1990/ratelimiter
- Owner: Rapter1990
- Created: 2024-06-28T20:22:04.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-02T19:37:07.000Z (5 months ago)
- Last Synced: 2024-07-04T14:54:30.736Z (5 months ago)
- Topics: cicd, docker, docker-compose, github-actions, integration-test, java, java21, junit, lombok, maven, postman, redis, spring-boot, testcontainer
- Language: Java
- Homepage:
- Size: 4.24 MB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RATE LIMITER WITH REDIS
### 📖 Information
- This application is a Spring Boot application demonstrating rate limiting with Redis for user management operations.
-
Explanation:
-
UserController: The API endpoint for managing user information. It includes methods to handle creating, retrieving, updating, and deleting user data. This controller interacts with the UserService to perform these operations. -
UserService: Contains the business logic for user management. It performs CRUD operations on the User entity and interacts with the RateLimiterService to apply rate limiting rules. -
RateLimiterService: Utilizes Redis to track and enforce rate limiting rules. It ensures that the number of requests made by a user does not exceed the specified limit within a given time window. -
UserRepository: Extends Spring Data JPA's JpaRepository, providing methods for performing database operations on user entities. This layer abstracts the data access operations, making it easier to manage user data. -
Redis Configuration: Redis is configured to support rate limiting functionality. The configuration includes setting up a RedisTemplate for efficient data access and operations. This template handles the interactions with Redis, such as incrementing request counts and setting expiration times for keys, ensuring accurate rate limiting. -
Validation: The application uses Hibernate Validator for validating user input. This ensures that the data passed to the API endpoints is in the correct format and adheres to the defined constraints. -
Exception Handling: Custom exception handling mechanisms are implemented to manage various error scenarios, such as user not found, email already exists, and rate limit exceeded.
-
### Explore Rest APIs
Method
Url
Description
Request Body
Header
Valid Path Variable
Request Param
No Path Variable
POST
/api/v1/users/save
Create a new user
CreateUserRequest
GET
/api/v1/users/{id}
Retrieve a user by ID
{id} - Valid UUID
PUT
/api/v1/users/{id}
Update an existing user
UpdateUserRequest
{id} - Valid UUID
DELETE
/api/v1/users/{id}
Delete a user by ID
{id} - Valid UUID
GET
/api/v1/users
Retrieve a paginated list of users
UserPagingRequest
---
### Technologies
- Java 21
- Spring Boot 3.0
- Restful API
- Lombok
- Maven
- Junit5
- Mockito
- Integration Tests
- Docker
- Docker Compose
- CI/CD (Github Actions)
- Postman
- Spring Bean Validation
---
### Postman
```
Import postman collection under postman_collection folder
```
---
### Prerequisites
#### Define Variable in .env file
```
DATABASE_USERNAME={DATABASE_USERNAME}
DATABASE_PASSWORD={DATABASE_PASSWORD}
```
---
- Maven or Docker
---
### Docker Run
The application can be built and run by the `Docker` engine. The `Dockerfile` has multistage build, so you do not need to build and run separately.
Please follow directions shown below in order to build and run the application with Docker Compose file;
```sh
$ cd ratelimiter
$ docker-compose up -d
```
If you change anything in the project and run it on Docker, you can also use this command shown below
```sh
$ cd ratelimiter
$ docker-compose up --build
```
---
### Maven Run
To build and run the application with `Maven`, please follow the directions shown below;
```sh
$ cd ratelimiter
$ docker run --name redis -p 6379:6379 -d redis
$ mvn clean install
$ mvn spring-boot:run
```
---
### Docker Image Location
```
https://hub.docker.com/repository/docker/noyandocker/ratelimiter/general
```
---
### Screenshots
Click here to show the screenshots of project
Figure 1
Figure 2
Figure 3
Figure 4
Figure 5
Figure 6
Figure 7
Figure 8
### Contributors
- [Sercan Noyan GermiyanoÄŸlu](https://github.com/Rapter1990)