This project contains two microservices: User Service and Notification Service. They communicate via RabbitMQ to handle user-related events and send notifications (email, push, SMS). PostgreSQL is used for data storage in the User Service.
- User Service: Manages user operations and publishes notification events.
- Notification Service: Listens to events and sends notifications.
- RabbitMQ: Message broker for asynchronous event communication.
- PostgreSQL: Database for User Service.
- NestJS (TypeScript)
- RabbitMQ
- PostgreSQL 16
- Docker & Docker Compose
- Axios (used in Notification Service to simulate push notifications)
Service | Description | Ports |
---|---|---|
postgres |
PostgreSQL database | 5432:5432 |
rabbitmq |
RabbitMQ broker and management UI | 5672:5672 , 15672:15672 |
user-service |
User microservice API and event publisher | 3000:3000 |
notification-service |
Notification microservice (consumer and sender) | 5000:5000 |
-
Clone the repository:
git clone <your-repo-url> cd <your-repo>
-
Create .env files:
cp ./user-service/.env.example ./user-service/.env
cp ./notification-service/.env.example ./notification-service/.env
-
Start all services:
docker-compose up --build
-
Access the services:
- User Service API: http://localhost:3000
- Notification Service API: http://localhost:5000
- RabbitMQ Management UI: http://localhost:15672
POST http://localhost:3000/users
Content-Type: application/json
{
"name": "Andrii"
}
- The User Service performs user actions (e.g., registration).
- It publishes a notification event with type and payload to RabbitMQ.
- The Notification Service listens for events from RabbitMQ.
- When an event is received:
- It selects the right notification channel (push).
- Uses a Message Template Resolver to create a title and body for the notification based on event type.
- Sends the notification via the corresponding service (e.g.,
PushService
sends an HTTP POST to the webhook URL).
- Notifications are logged for monitoring.