A Spring Boot microservice responsible for inventory management in the event-driven order platform. It participates in distributed sagas as a Kafka consumer/producer, reserving stock as part of the order fulfillment flow coordinated by the Saga Orchestrator.
| Property | Value |
|---|---|
| Port | 8082 |
| Java | 17 |
| Spring Boot | 4.0.3 |
| Database | PostgreSQL (inventory_db) |
| Messaging | Apache Kafka |
Kafka and PostgreSQL must be running before starting the service. Start them via Docker Compose from the shared infrastructure:
cd ~/Workspace/event-driven-simulator/infrastructure/docker-compose
docker compose up -dThis provides:
- Kafka (KRaft mode) — external:
localhost:9094, inter-container:kafka:9092 - PostgreSQL —
localhost:5432, database:inventory_db
mvn spring-boot:runThe service will be available at http://localhost:8082.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/v1/inventory/{productId} |
Get inventory item by product ID |
POST |
/api/v1/inventory/ |
Add a new inventory item |
curl -X POST http://localhost:8082/api/v1/inventory/ \
-H "Content-Type: application/json" \
-d '{"productId": "prod-123", "availableQuantity": 100}'curl http://localhost:8082/api/v1/inventory/prod-123| Direction | Topic | Event |
|---|---|---|
| Consumes | order.inventory.reserve |
ReserveInventoryCommand |
| Produces | order.inventory.reserved |
InventoryReservedEvent |
| Produces | order.inventory.failed |
InventoryReservationFailedEvent |
- Saga Orchestrator publishes a
ReserveInventoryCommandtoorder.inventory.reserve - This service looks up the item by
productId - If found and stock is sufficient → decrements quantity, publishes
InventoryReservedEvent - Otherwise → publishes
InventoryReservationFailedEventwith reason:"Product not found""Insufficient stock"
mvn test # Run all tests
mvn test -Dtest=ClassName # Run a single test class
mvn spotless:apply # Auto-format (Google Java Format)
mvn spotless:check # Verify formatting
mvn clean install # Full buildBefore committing:
mvn spotless:applymvn spotless:checkmvn test
src/main/java/com/platform/inventoryservice/
├── config/ Kafka consumer and producer configuration
├── controller/ REST endpoints
├── service/ Reservation business logic
├── model/ InventoryItem JPA entity
├── repository/ Spring Data JPA repository
├── messaging/
│ ├── consumer/ Kafka listener for ReserveInventoryCommand
│ └── producer/ Kafka publisher for result events
├── event/
│ ├── inbound/ ReserveInventoryCommand DTO
│ └── outbound/ InventoryReservedEvent, InventoryReservationFailedEvent DTOs
└── exception/ InventoryItemNotFoundException, GlobalExceptionHandler