DDD+CQRS+EventSourcing+Hypermedia API+ASP.NET Core 3.1+Masstransit+terraform+docker+k8s
The example is regarding online booking/checkin for an airline company. An airline company named 'RestAirline' is offering online booking/checkin. There are four possible Bounded context for above business:
Booking
is a bounded context that focusing on online booking;Flight Availability
is a bounded context that focusing searching available flights and flight schedule;Checkin
is a bounded context that focusing on online checkin;Seat Availability
is a bounded context that maintaining seat for each flight;
Generally each bounded context can be build as a standalone Microservice, For now I just created two Microservices: Booking
and FlightAvailability
.
There are some interactions between these two Microservices, the obvious action is when passenger selected flight in Booking
Microservice,
The available amount of flights in FlightAvailability
Microservice should subtract corresponding amount. The idea is when passenger selected a flight in Booking
service, A event named JourneysSelectedEvent
will be published to message bus, Any Microservices who are interested in this event can subscribe this event
and handle it.
Then spin up a new container using docker-compose
docker-compose up
Note: add a -d
to run the container in background
An API service and mssql will run in docker
This project based on .NET Core 3.1, please install corresponding SDK for your operating system:
After installing, please run below command to make sure current .NET Core version is 3.1.101
dotnet --version
Journey items should come from another micro-service named flight availability, for now let's build a journey in the api automatically for convenience. So you need not pass any journey id to this api.
POST /booking/journeys
We can get request body schema from last Api response become the whole Api is designed by Hypermedia.
The api definition is totally described by last api response under resourceCommands\addPassengerCommand
:
"addPassengerCommand":
{
"bookingId": "booking-352cb1f3-0f68-4e04-a2f7-24036eb53ce7",
"name": null,
"passengerType": 0,
"age": 0,
"email": null,
"postUrl": {
"uri": "/booking/booking-352cb1f3-0f68-4e04-a2f7-24036eb53ce7/passenger"
}
}
Obviously the endpoint is:
http://localhost:61100/booking/booking-352cb1f3-0f68-4e04-a2f7-24036eb53ce7/passenger
The payload schema is:
{
"bookingId": "booking-352cb1f3-0f68-4e04-a2f7-24036eb53ce7",
"name": null,
"passengerType": 0,
"age": 0,
"email": null,
}
bookingId
is filled already, please try to fill other parameters, eg:
{
"bookingId": "booking-352cb1f3-0f68-4e04-a2f7-24036eb53ce7",
"name": "test",
"passengerType": 0,
"age": 22,
"email": "[email protected]",
}
Send request:
POST booking/{bookingId}/passenger
According to response of last api, you can either get the booking by resourceLinks
or post data by resourceCommand
.
GET /booking/{bookingId}
The example is regarding online booking for an airline company. An airline company named 'RestAirline' is offering online booking.
2h <= timeWindow <= departure time - 30m