This is a simple demo of a microservices architecture using NATS as the messaging system. The demo is based on a "coffee shop" scenario where clients can order coffee in an automated way.
The demo consists of the following components:
routes
- a service that exposes a web interface for clients to order coffee.controller
- a service that receives the orders from theroutes
service, check the stock (using thestock
service) and send the order tocoffee-makers
services.stock
- a service that keeps track of the stock of coffee beans in a database.coffee-makers
- a service that receives the orders from thecontroller
service and makes the coffee. The service updates the stock in thestock
service when an order is completed.
You will need to have a NATS server running. Set an environment variable NATS_SERVER
and run each service with go run
.
export NATS_SERVER=localhost:4222
cd routes && go run main.go &
cd controller && go run main.go &
cd stock && go run main.go &
cd coffee-makers && go run main.go &