A sample project to experiment with MassTransit Saga, for service to service communication patterns and also explore tools that can help improve local development. Feel free to post an issue if you have improvements you'd like to propose.
- Docker 🐋
- .NET 6
- Visual Studio 2022 (recommended) or VS Code for debugging
- Customers (Web API)
- Orders (Web API)
- Notifications (Hosted Service)
- Seq (http://localhost:5341/)
- RabbitMQ (http://localhost:15672/)
- NoSQL Client (http://localhost:5000/)
- Customers API (http://localhost:5001/)
- Orders API (http://localhost:5002/)
There's a docker-compose.yml file within the root of the repository. Just fire up your command-line then type in docker-compose up -d to run everything. This repo should be ready to run and debug locally out of the box. If you are using Visual Studio 2022, you can also select the docker-compose project as the startup project and run+debug the application if you wish to follow along and see how this works.
- Go to http://localhost:5000/
- Hit
Connectfrom the top-right corner of the page - The
Connectionswindow will show up, click theCreate Newbutton - Enter a connection name
- Copy and paste
mongodb://masstransit.demo.mongo/customersdb?retryWrites=true&w=majorityinto theConnection URLtext field - Click on
Host/Porttextbox to parse the connection URL into the text fields
Know that the collections dropdown will be empty but once you register a new user, you should see a customers collection right below it if expanded.
There are currently 2 commands that you can execute for now; Registration and (fake) activation. I plan to add more as I find more time to code.
For user registration use the curl command below. When a user registers a CustomerRegisteredEvent gets published to the bus (through MassTransit + RabbitMQ) for Notifications service to be consumed by CustomerRegisteredConsumer. In a real-world scenario; this service should send out an email or SMS to the user containing the activation code.
curl --location --request POST 'https://localhost:5001/customers/register' \
--header 'Content-Type: application/json' \
--data-raw '{ "FirstName": "Joe", "LastName": "Smith", "Email": "joe.smith@gmail.com", "Phone": "1-314-123-4567" }'
Then after user registration, the account will be in a PendingActivation state. Use the curl command below to activate a user. Do not forget t change the <customer> id to the new user's customer id.
curl --location --request GET 'https://localhost:5001/customers/activate/<customer-id>/test-activation'