The Bakery Service is a gRPC server written in Go that manages several operations for a virtual bakery shop. The server provides functionality for checking inventory, making bread, buying bread, and removing old bread. It uses RabbitMQ for asynchronous message passing and PostgreSQL for persistent data storage.
- Go: The language used to develop this application. Ensure you have Go installed on your system.
- gRPC: Used for handling remote procedure calls.
- RabbitMQ: Used for message queueing. This allows the bakery service to consume and publish messages asynchronously.
- PostgreSQL: The database used for data persistence.
The Bakery Service needs a running RabbitMQ instance and PostgreSQL database.
Set the following environment variables:
BAKERY_SERVICE_ADDR
: The address for the Bakery Service gRPC serverRABBITMQ_SERVICE_ADDR
: The address for the RabbitMQ serverDSN
: The PostgreSQL database connection string
For development on local environments:
export BAKERY_SERVICE_ADDR=localhost:50051
export RABBITMQ_SERVICE_ADDR=amqp://guest:guest@localhost:5672/
Some useful commands
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/bread.proto
docker build . -t docker.io/calvarado2004/bakery-go-buyers -f buyers.dockerfile && docker push docker.io/calvarado2004/bakery-go-buyers
docker build . -t docker.io/calvarado2004/bakery-go-frontend -f frontend.dockerfile && docker push docker.io/calvarado2004/bakery-go-frontend
docker build . -t docker.io/calvarado2004/bakery-go-makers -f makers.dockerfile && docker push docker.io/calvarado2004/bakery-go-makers
docker build . -t docker.io/calvarado2004/bakery-go-server -f server.dockerfile && docker push docker.io/calvarado2004/bakery-go-server
Install the Go dependencies with:
go mod download
Start the application with:
go run main.go
The Bakery Service runs several background tasks to handle the bakery operations:
- Check Bread: Every 30 seconds, the bakery checks the bread inventory and sends a message to the RabbitMQ queue make-bread-order if more bread needs to be made.
- Perform Buy Bread: The service consumes messages from the RabbitMQ queue buy-bread-order and processes the buying operation.
- gRPC Server: The gRPC server listens for incoming requests and handles them accordingly.
The Bakery Service provides several gRPC endpoints:
- CheckInventoryServer: Checks the current inventory of the bakery.
- MakeBreadServer: Makes bread based on the given order.
- BuyBreadServer: Processes the purchase of bread.
- RemoveOldBreadServer: Removes old bread from the inventory.
If you face any issues while setting up or running the Bakery Service, here are a few things to check:
- RabbitMQ Connection: Make sure your RabbitMQ server is running and accessible from the Bakery Service.
- PostgreSQL Connection: The Bakery Service needs to connect to a PostgreSQL database. Ensure it is running and accessible, and the connection string is correct.
- Environment Variables: Verify that all necessary environment variables are set.