Hello World with multiple microservices
A friend of mine was having trouble finding simple but working example of microservices that he could tinker with, finding instead either buzzword-heavy theoretical articles or just samples in weird languages. I decided to prepare a simple project so it can be understood in short amount of time.
The sample project is modeling a “Starbucks-style” coffee ordering process with a cashier, barista and order pick up counter with the following flow:
sequenceDiagram participant Customer participant Cashier participant Barista participant PickUpCounter Customer->>Cashier: Order drink and pay Cashier->>Barista: Relay customer order Note over Barista: prepares the drink Barista->>PickUpCounter:Bring prepared drink Note over PickUpCounter: Announce that the drink is ready
The sample project
For a tech stack, I will be using the awesome MassTransit with RabbitMq as transport and a client process that would send REST requests that “simulate” drink orders.
Here is a quick breakdown of what happens in the sample project:
- Client process sends random drink orders via POST http requests
- Cashier receives client orders via POST request and puts it into a received orders queue (BlockingCollection{T})
1 | //Nancy module to serve as API for registering orders |
And finally, PickUpCounter would receive the event of completed order and announce it to customers
Note that the actual “business logic” code is interleaved with infrastructure code and there is (almost) no logging and error handling. This is something that obviously shouldn’t happen in production-level code - this stuff is left out for better readability of code.
Getting and running the project
- You can get the project from its Github repository.
- Compiling and running it would require .Net Core 3.0 SDK.
- Running the project depends on local installation of RabbitMq. Take a look here for RabbitMq install instructions.