A robust, scalable notification service built with Spring Boot, designed to handle multi-channel notifications including Email, SMS (via Twilio), and Push Notifications (via Firebase). This service uses an event-driven architecture with RabbitMQ to ensure high availability and reliability.
- Multi-channel Support: Send notifications via Email, SMS, and Push.
- Event-Driven Architecture: Decoupled notification processing using RabbitMQ.
- Persistence: Stores notification history and status in MongoDB.
- Scalable: Dockerized and ready for deployment.
- RESTful API: Simple endpoints to trigger and retrieve notifications.
- Core: Java 17, Spring Boot 4+
- Database: MongoDB
- Message Broker: RabbitMQ
- Integrations:
- Email: Java Mail Sender (SMTP)
- SMS: Twilio
- Push: Firebase Cloud Messaging (FCM)
- Containerization: Docker, Docker Compose
- Tools: Lombok, Maven
Before running the application, ensure you have the following installed:
- Java 17+
- Docker & Docker Compose
- Maven (optional, included via wrapper)
The application relies on environment variables for sensitive configuration. You can set them in a .env file in the root directory.
Create a .env file in the project root with the following structure:
# Server
SERVER_PORT=8080
# MongoDB
MONGODB_HOST=mongodb
MONGODB_PORT=27017
MONGODB_DATABASE=notification_db
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=password
# RabbitMQ
RABBITMQ_HOST=rabbitmq
RABBITMQ_PORT=5672
RABBITMQ_DEFAULT_USER=guest
RABBITMQ_DEFAULT_PASS=guest
# Email (Gmail SMTP example)
MAIL_USERNAME=your_email@gmail.com
MAIL_PASSWORD=your_app_password
# Twilio (SMS)
TWILIO_ACCOUNT_SID=your_twilio_sid
TWILIO_AUTH_TOKEN=your_twilio_auth_token
TWILIO_FROM_NUMBER=your_twilio_number
# Firebase (Push)
FIREBASE_CONFIG_PATH=classpath:firebase/firebase-service-account.jsonThis requires no manual local setup of MongoDB or RabbitMQ.
- Build and Run:
docker-compose up -d --build
- The application will be available at
http://localhost:8080. - To stop:
docker-compose down
- Start Infrastructure:
Ensure you have MongoDB and RabbitMQ running locally or use Docker for just the infra:
docker-compose up -d mongodb rabbitmq
- Run Application:
./mvnw spring-boot:run
POST /api/v1/notifications/send
{
"recipient": "+1234567890",
"subject": "Welcome!",
"content": "Thanks for signing up.",
"type": "SMS"
}Types: SMS, EMAIL, PUSH
GET /api/v1/notifications
GET /api/v1/notifications/{id}
- Client sends a POST request to
/api/v1/notifications/send. - Controller receives the request and validates it.
- Service saves the notification with status
PENDINGto MongoDB. - Producer sends the Notification ID to RabbitMQ.
- Consumer listens to the queue, picks up the ID, and retrieves full details from MongoDB.
- Channel Resolver determines the correct channel (SMS, Email, Push) and dispatches the message via the corresponding 3rd party API.
- Service updates the notification status to
SENTorFAILEDin MongoDB.