This project consists of two microservices: Document Service and Notification Service.
-
document-service/
- Dockerfile
-
notification-service/
- Dockerfile
-
docker-compose.yml
-
settings.gradle.kts
The Document Service is responsible for managing freelancer documents. It allows freelancers to add, update, and delete their documents. One freelancer can have multiple documents. After every successful verification, the Document Service calls the Notification Service to process and distribute relevant notifications.
The Notification Service receives and processes notifications generated from the Document Service API. It handles the distribution of these notifications and saves them into the database.
-
RabbitMQ: Used to receive notifications from the
NotificationController.java
and forward them to a queue. -
Spring Boot Default Cache: Applied on the Document model for caching. The cache is updated after database operations.
-
MongoDB:
- Reactive MongoDB is used for the Notification Service.
- Non-reactive MongoDB is used for the Document Service.
-
Containerization: Both services are containerized and can be deployed using
docker-compose.yml
. -
The caching interface is available and can be accessed via the API to view the amount of data currently stored in the cache. This cache uses Spring Boot's simple in-memory cache mechanism and has been applied to the document API. The interface allows you to monitor the cache data.
The API uses a standardized response structure for both successful responses and error scenarios.
For successful API calls, the response structure follows the ResponseDto<T>
format:
public class ResponseDto<T> {
private T data;
private String message;
// ... constructors and other methods
}
For error scenarios, including DTO field validation failures, runtime exceptions, and other failure cases, the response structure follows the ApiError
format:
public class ApiError {
private HttpStatus status;
private String message;
private List<String> errors;
// ... constructors and other methods
}
This ApiError
class is used to provide a consistent error response structure across the API. It includes:
- HTTP status code of the error
- A general error message
- A list of specific error details, which is particularly useful for field validation errors
Whether it's a validation error on a DTO, a runtime exception, or any other type of failure, the API will use this ApiError
structure to communicate the problem to the client.
This section provides instructions on how to run the project using different methods.
You have two options to run this project:
- Using Docker Compose (Recommended)
- Building and Running Services Independently
To start the entire project using Docker Compose:
- Navigate to the root folder of the project.
- Run the following command:
This will start MongoDB, RabbitMQ, and both microservices.
docker-compose up --build
If you prefer to run services independently, follow these steps:
-
Install MongoDB:
docker run -d --name mongodb -p 27017:27017 mongo:latest
-
Install RabbitMQ:
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:latest
The Document Service depends on Spring Boot's internal cache (In memory cache). You can run it in two ways:
-
Through an IDE:
- Update
application.yml
:spring: data: mongodb: uri: ${SPRING_DATA_MONGODB_URI:mongodb://localhost:27017/documentdb} notification: service: url: ${NOTIFICATION_SERVICE_URL:http://localhost:8081/v1/api/notifications}
- Run the main application class.
- Update
-
Using Docker:
- Build the image:
docker build --no-cache -f document-service/Dockerfile -t document-service:latest .
- Run the container:
docker run -p 8080:8080 document-service:latest
- Build the image:
The Notification Service depends on both MongoDB and RabbitMQ. You can run it in two ways:
-
Through an IDE:
- Update
application.yml
:spring: data: mongodb: uri: ${SPRING_DATA_MONGODB_URI:mongodb://localhost:27017/notificationdb} rabbitmq: host: ${SPRING_RABBITMQ_HOST:localhost} port: ${SPRING_RABBITMQ_PORT:5672} username: guest password: guest
- Run the main application class.
- Update
-
Using Docker:
- Build the image:
docker build --no-cache -f notification-service/Dockerfile -t notification-service:latest .
- Run the container:
docker run -p 8081:8081 notification-service:latest
- Build the image:
Both services have Swagger UI enabled for API documentation:
- Document Service:
http://localhost:8080/swagger-ui/index.html
- Notification Service:
http://localhost:8081/swagger-ui/index.html
Health check endpoints are available via Spring Boot Actuator:
- Document Service:
http://localhost:9090/actuator/health
- Notification Service:
http://localhost:9091/actuator/health
These endpoints can be used to monitor the health of the services in a production environment.