Implementing Microservice Architecture In .NET Part 1 , Project Overview
Hi everyone :)
Next Articles:
Implementing Microservice Architecture In .NET Part 2 , Auth Service by JWT Token
Implementing Microservice Architecture In .NET Part 3 , Product Service
In a few articles, I plan to write a small project together with Microservice Architecture for exchange some information about this , the things that are said are my opinion and you may have a different opinion that is respected by me and you can write in the comments section :)
You can see the project source in this Github Repository
Our example is a shop , we have six microservices that is Asp Core Web API On .Net 6
- AuthMicroservice : Register User And Login Services
- ProductsMicroService : Add Edit Update Products Category And Products
- BasketMicroService : Our Shop Basket , Add Edit And Delete Basket Items And Use DiscountCode In Basket
- DiscountMicroservice : Add Edit Delete Discount Code
- OrderMicroService : Save Orders , See Order Details
- PaymentMicroService : Pay Our Orders
and have one endpoint for our UI that is a ASP Core Mvc Project
at last a API Getway by Ocelot
We can see the implementing schema in the picture
Technologies used in the project
- Ocelot For Api Getway
- RabbitMQ For Message Broker
- JWT Token For Authentication And Authorization
- SQL Server And MongoDB For Databases
- ASP Core Web Api For Our Rest Api And Swagger As Open API
- Google RPC (GRPC) For Transfer Data Between Microservice
- Docker For Run Database Services ( SQL Server , MongoDB ) And Message Broker ( RabbitMQ )
How Run Project
for run this project we need some service , there is SQL Server , RabbitMQ and MongoDB
if like me some service have installed before , you can just run the service is not installed , for example i have sqlserver and mongodb in my system , so just run rabbitmq by docker by this code
docker run --rm -it -p 15672:15672 -p 5672:5672 rabbitmq:3-management
then we can run project :) , notice that if use installed service the connection in appsettings.json file in projects must be config as the installed information
for example I use sql server by this connection string , and must change appsettings.json project file to config it.
Server=.; Initial Catalog=AuthDB;Integrated Security=True;MultipleActiveResultSets=True
you can see separate run code service by docker
For Run Separatly On Docker
Run RabbitMQ:
docker run --rm -it -p 15672:15672 -p 5672:5672 rabbitmq:3-management
Run Sql Server:
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=str0ngp@ssword" -e "MSSQL_PID=Express" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest
Run MongoDB:
docker run -d -p 27017:27017 --name example-mongo mongo:latest
but if you do not use installed service , like my laptop , just run the docker compose command to install and run services and do not need to change appsettings.json file because the configs is set for docker file.
just run docker-compose up command in the folder has the file docker-compose.yml ( in the root of project files)
all the service are up and just must run project :)
its better run all project together , for do this right click on solution file and click properties and select multiple startup project and start all service except ShareServices project that is a class library.
if we start the project all microservice will be run on different port and can see all projects :).
If you have any problems with the run of the project, you can ask me in the comments :)
In the next article, we will go to develop AuthMicroservice and continue our work.
Of course, we still have a lot of work to do, but you can see the full source of these articles here.
I hope you like this article :)
Next Article
Implementing Microservice Architecture In .NET Part 2 , Auth Service by JWT Token
Implementing Microservice Architecture In .NET Part 3 , Product Service