The Product Service manages product information and inventory within our microservices architecture.
- Product creation, updates, and deletions
- Inventory management
- Event emission for product-related actions
- Inventory update on receiving order related events
- Node.js
- Express.js
- MongoDB
- Kafka for event streaming
-
Navigate to the product-service directory:
cd product-service
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file in the product-service directory and add:PORT=5002 MONGO_URL=mongodb://localhost:27017/product-db KAFKA_BROKER=localhost:29092
-
Start the service:
npm start
The service is automatically deployed when you run docker-compose up
from the root directory. It will be available at http://localhost:5002
.
POST /api/products/create
: Create a new productGET /api/products/getallproducts/all
: Get all productsGET /api/products/get/:productId
: Get a specific productPUT /api/products/updateprice/:productId"
: Update a product pricePUT /api/products/updateinventory/:productId
: Update product inventory
This service emits the following Kafka events:
- "product-created": When a new product is added
- "inventory-updated": When product inventory is updated
This service listens for:
- "order-placed": To update inventory when an order is placed