A Spring Boot microservice that accepts notification requests over HTTP, persists them in MongoDB, and processes email delivery asynchronously via RabbitMQ.
- A client sends a
POST /api/notificationsrequest. - The notification is saved to MongoDB with status
PENDING. - A message is published to RabbitMQ.
- A consumer picks up the message and sends the email via Mailtrap SMTP.
- The notification status is updated to
SENTorFAILED.
Failed messages are routed to a dead-letter queue for later inspection.
- Java 26
- Spring Boot 4.1
- MongoDB Atlas
- RabbitMQ
- Mailtrap (SMTP)
- Maven
- Java 26+
- Maven (or use the included
./mvnwwrapper) - Docker (for local RabbitMQ)
- MongoDB connection string
- Mailtrap SMTP credentials
git clone <repository-url>
cd notification-service-applicationCopy the example env file and fill in your values:
cp .env.example .envRequired variables:
| Variable | Description |
|---|---|
MONGODB_URI |
MongoDB connection string (Atlas) |
MAIL_USERNAME |
Mailtrap SMTP username |
MAIL_PASSWORD |
Mailtrap SMTP password |
The app loads .env automatically via spring.config.import in application.yml. Do not commit .env — it is listed in .gitignore.
docker compose up -dRabbitMQ will be available at:
- AMQP:
localhost:5672 - Management UI: http://localhost:15672 (guest / guest)
./mvnw spring-boot:runOn Windows:
mvnw.cmd spring-boot:runThe service starts on http://localhost:8080.
GET /api/healthPOST /api/notifications
Content-Type: application/json
{
"recipient": "user@example.com",
"subject": "Welcome",
"body": "Thanks for signing up!"
}Response 201 Created:
{
"id": "6a5941134a9541fd3c6b2fef",
"recipient": "user@example.com",
"subject": "Welcome",
"status": "PENDING",
"createdAt": "2026-07-16T20:37:39.148Z"
}GET /api/notifications/{id}Response 200 OK:
{
"id": "6a5941134a9541fd3c6b2fef",
"recipient": "user@example.com",
"subject": "Welcome",
"status": "SENT",
"createdAt": "2026-07-16T20:37:39.148Z"
}GET /api/ping| Status | Meaning |
|---|---|
PENDING |
Saved and queued, email not yet sent |
SENT |
Email delivered successfully |
FAILED |
Email delivery failed (see failureReason) |
Main settings live in src/main/resources/application.yml. Sensitive values are injected from .env:
spring:
mongodb:
uri: ${MONGODB_URI}
mail:
host: sandbox.smtp.mailtrap.io
port: 2525
username: ${MAIL_USERNAME}
password: ${MAIL_PASSWORD}RabbitMQ queue and exchange names are under the notification.rabbitmq prefix in application.yml.
Health and metrics endpoints are exposed at /actuator:
/actuator/health/actuator/info/actuator/metrics
src/main/java/com/mogeni/notificationserviceapplication/
├── config/ # MongoDB, RabbitMQ configuration
├── controller/ # REST endpoints
├── dto/ # Request/response objects
├── entity/ # MongoDB documents
├── exception/ # Custom exceptions
├── repository/ # Spring Data MongoDB repos
└── service/ # Business logic, producer, consumer, email
./mvnw test