One of three microservices in the CSCI 44092 e-commerce backend. It listens to order events on RabbitMQ and logs a mock notification. No database — it only consumes messages and logs.
Order Service --(publishes OrderCreatedEvent)--> RabbitMQ --> Notification Service (logs notification)
The Order Service publishes an event to the order.created.queue queue when an order is created.
This service consumes those messages and logs the notification details.
- Java 21, Spring Boot
- Spring AMQP (RabbitMQ)
- springdoc-openapi (Swagger UI)
- JUnit 5 + Mockito for tests
Credentials are externalized via environment variables (with local-friendly defaults):
| Variable | Default | Used by | Description |
|---|---|---|---|
RABBITMQ_HOST |
localhost |
app | RabbitMQ host |
RABBITMQ_PORT |
5672 |
app + compose | RabbitMQ port |
RABBITMQ_USER |
myuser |
app + compose | RabbitMQ username |
RABBITMQ_PASS |
secret |
app + compose | RabbitMQ password |
RABBITMQ_MGMT_PORT |
15672 |
compose | RabbitMQ management UI host port |
Both the app and Docker Compose read these from a .env file. Copy the template and adjust:
cp .env.example .env.env is gitignored so real secrets are never committed. Docker Compose loads .env
automatically. The Spring app falls back to the defaults above when a variable is unset.
See application.properties and
.env.example.
RabbitMQ runs as its own container (compose.yaml) and the Notification Service runs
as a separate container (compose.app.yaml). They share the notification-net
Docker network, so the app reaches the broker by service name (RABBITMQ_HOST=rabbitmq).
-
Start RabbitMQ (broker + management UI):
docker compose -f compose.yaml up -d
Management UI: http://localhost:15672 (user
myuser, passwordsecret). -
Build and start the Notification Service container:
docker compose -f compose.app.yaml up -d --build
The app is published on host port 8081 by default (host 8080 is often taken by a local Apache). Override with
APP_PORT:APP_PORT=9090 docker compose -f compose.app.yaml up -d --build
-
Tail the logs to watch notifications:
docker compose -f compose.app.yaml logs -f notification-service
From the RabbitMQ container (or the management UI → Queues → order.created.queue → Publish):
docker exec notification-service-rabbitmq-1 rabbitmqadmin --username myuser --password secret \
--non-interactive publish message -k order.created.queue \
-m '{"orderId":1,"customerId":42,"productId":7,"productName":"Wireless Mouse","quantity":2,"totalPrice":59.98}'Instead of step 2, you can run the jar directly with ./gradlew bootRun. Spring Boot's
docker-compose support will auto-start compose.yaml if Docker is available. (This is dev-only;
spring-boot-docker-compose is not packaged into the container image.)
Queue: order.created.queue
Expected JSON payload (OrderCreatedEvent):
{
"orderId": 1,
"customerId": 42,
"productId": 7,
"productName": "Wireless Mouse",
"quantity": 2,
"totalPrice": 59.98
}When a message is received, the service logs the notification (order id, customer id, message,
timestamp). You can publish a test message manually from the RabbitMQ management UI
(Queues → order.created.queue → Publish message).
Set
content_type=application/jsonwhen publishing manually, or the message can't be deserialized.
With the app running on host port 8081 (the default — see "Running locally"):
- Swagger UI: http://localhost:8081/swagger-ui/index.html
- OpenAPI JSON: http://localhost:8081/v3/api-docs
Endpoints:
GET /notifications/status— service health/status endpoint.
Run the unit tests (no Docker or RabbitMQ required):
./gradlew test # Git Bash / Linux / macOS
.\gradlew test # Windows PowerShellThe tests cover the notification service logic and the RabbitMQ listener (including error handling).
The HTML report is written to build/reports/tests/test/index.html.
The Order Service is the publisher; this service is the consumer. For a step-by-step guide on cloning, running both containers, publishing events, and verifying the notification log, see docs/ORDER_SERVICE_INTEGRATION.md.
src/main/java/com/pm/notificationservice/
├─ config/ RabbitMQConfig, OpenApiConfig, SecurityConfig
├─ controller/ NotificationStatusController (status endpoint for Swagger)
├─ messaging/ OrderEventListener, OrderCreatedEvent
├─ model/ Notification
└─ service/ NotificationService
compose.yaml RabbitMQ broker container
compose.app.yaml Notification Service container
Dockerfile Multi-stage build for the service image