This part belong to a serie of articles about dapr :
- Introduction to dapr
- Service Invocation
- Publish-Subscribe pub/sub
- State management
- Hosting using AKS (Azure Kubernetes Services)
In the previous part, we have introduced dapr ,now we are going to start creating our services one by one for that and as a start what we need is :
- Make sure Docker is running and Dapr services too .
- Have .Net 5 Insatlled
- Have visual studio installed .
Creating the API :
First of all we are going to create and empty solution and name it as you want to , and than we are need to add a : ASP .NET WEB API project to the solution or you can just type
dotnet new webapi
The full solution can be found at this link : https://bit.ly/3s5pz5C
Now, you may run the solution by running the following command :
after that when we go to visit: http://localhost:3902/api/cookies we will get as return a list of cookies
Runing the API :
What we really want to do is to run the solution using Dapr for that and in order to expose the cookies api using the dapr sidecar we need to run the command :
dapr run --app-id cookiesstoreapi --app-port 5001 --dapr-http-port 50001 dotnet run
This may be a bit strange for you so let’s explain all the parts of this command :
- –app-id : each app/service must have a unique ID .
- –app-port : in launch settings i changed the parameters so the app runs on port 5001 when I use dotnet run.
- –dapr-http-port : the port that dapr in listening to for this service.
- dotnet run : this is how we run dotnet applications
Now when we run this cmd we can still get our cookirs from http://localhost:5001/api/cookies but also now we can get them from the side car using : http://localhost:50001/v1.0/invoke/cookiesstoreapi/method/api/cookies .
Discovering the Services :
using the follow command we can see the running services by dapr :
On http://localhost:8080/ u will find dapr dashboard that will present to you the running services also the dapr components :
When the dapr is working and by veryfing the runing containers, one of them is a Zipkin container, so what is zipkin ?
Zipkin is a distributed tracing system. It helps gather timing data needed to troubleshoot latency problems in service architectures. Features include both the collection and lookup of this data.
running: Docker ps will show us the following containers :
Zipkin let you trace your services and show you all the dependencies and we will see that in the next part .