In the order service, call the user service at http://localhost:3001/users/:id to verify the user exists before creating an order. Return 404 if user not found.
Express
Need a hint?
Use fetch to call the user service. Check userRes.ok for success. Wrap in try/catch to handle connection failures with a 502 response.
Add a circuit breaker to the HTTP call
Wrap the user service call with the opossum circuit breaker. If 3 requests fail within 30 seconds, open the circuit and return a fallback response instead of calling the service.
Express
Need a hint?
Create a function that fetches the user. Pass it to new CircuitBreaker with options for timeout and thresholds. Add a fallback with breaker.fallback(). Call with breaker.fire().
Publish an event after order creation
After successfully creating an order, publish an order_created event to a RabbitMQ queue so other services (notification, analytics) can react to it.
Express
Need a hint?
Connect to RabbitMQ once at startup. Use channel.assertQueue to create the queue. Use channel.sendToQueue to publish the order as a JSON buffer. Set persistent: true so messages survive restarts.
Create a notification service that consumes events
Create a separate Express service that consumes order_created events from RabbitMQ and logs a notification for each order.
Express
Need a hint?
Use channel.consume to listen for messages. Parse the JSON from msg.content. Always call channel.ack(msg) after processing so RabbitMQ removes the message from the queue. Use prefetch(1) to process one message at a time.