Currently, Microsoft has announced and published Dapr
to simplify the infrastructure tasks on local development and Kubernetes. It built for a developer who only wants to focus on the development of the application which inherently has a lot of complex business logic.
Dapr - An event-driven, portable runtime for building microservices on cloud and edge. See more at https://dapr.io
But with Dapr
, developers also need to care about how to run and compose docker images and a lot of Helm charts which are really complex too. So recently, they have published another tooling with named tye
.
Tye - A tool that makes developing, testing, and deploying microservices and distributed applications easier. Project Tye includes a local orchestrator to make developing microservices easier and the ability to deploy microservices to Kubernetes with minimal configuration. See more at https://github.com/dotnet/tye
As a developer, we want to build a great application with the best behavior and usability for end-users. But to build something that great also comes up with a lot of trouble when we are trying to find and fix bugs in the application. Normally, we are using a debug tool to overcome that obstacle.
At the moment, some guys at Microsoft have published some of the Visual Code extensions for debug the Dapr app. And one question that just comes to my mind that whether we can debug it using Visual Studio (forgive me because of my habit of using Visual Studio for a long time, and one more reason is using Resharper to increase my productivity in coding and refactoring codes). So I got no clue to find the way to debug the Dapr app on my Visual Studio so far.
But this week, when some of my colleagues at the company keeps talking a lot about tye
- a tool which helps to simplify the development with Docker
and without need to use docker-compose
as well as Helm
chart. After came home, I gave it a try and found out some of the interesting features of it. I spent sometimes to deep dive into it and raised some questions at its Github repository as well as doing some of the practice with Dapr. Thank you @davidfowl for his passion to explain and guide me to start with tye
. By walking through its documentation, I found out the way to debug the Dapr apps with this new tool. The remaining of this article will show you how to debug the Dapr application with it.
First off, we start with the high-level architecture of my application as below
Plz, forget ports inside the application on the picture above
The project structure is following
In this article, I will show you how to debug the inventory-api
which is hosted as the gRPC protocol on Dapr gRPC Server. And it is called product-catalog-api
.
The relationship of how our applications, tye
, and Dapr
as below
We have tye.yaml
file at the root of the project as below
name: practical-dapr
extensions:
- name: dapr
registry: dapracr.azurecr.io
services:
- name: sqlserver
image: mcr.microsoft.com/mssql/server:2017-latest
env:
- name: SA_PASSWORD
value: "P@ssw0rd"
- name: ACCEPT_EULA
value: "Y"
bindings:
- port: 1433
- name: redis
image: redis
bindings:
- port: 6973
- name: graph-api
project: src/GraphApi/CoolStore.GraphApi/CoolStore.GraphApi.csproj
- name: product-catalog-api
project: src/ProductCatalog/CoolStore.ProductCatalogApi/CoolStore.ProductCatalogApi.csproj
- name: inventory-api
project: src/Inventory/CoolStore.InventoryApi/CoolStore.InventoryApi.csproj
Open up the terminal and run
$ tye run
It will let you run all services and its docker image related. Open your browser and type http://localhost:8000
, you should see
All the applications with host
and port
have already been binding.
Now is the time we debug it. Close it and go back to your terminal and Ctrl + C
, then type
$ tye run --debug src/Inventory/CoolStore.InventoryApi
You can type
tye run --debug *
to debug all the applications
Now open up http://localhost:8000
, again
What you can see here is the difference between host
and port
of all Dapr applications in the project which means tye
will take care of dynamic host
and dynamic port
binding for our application. You don't need to care about declare your ports in your Dapr applications.
Open up your Visual Studio, and type Ctrl + Alt + P
, then choose the process with the name CoolStore.InventoryApi
as the picture below
Then go to your inventory-api
to set your debug point as
Now, back to your browser and click to http://localhost:64203
, and it should redirect you to the GraphQL playground, and type as below
{
products {
edges {
name
categoryName
inventoryLocation
}
totalCount
}
}
Click to Play
button, button as below
After clicking it, you should see the debug break-point will appear as below
Then, you can add a watch as
Finally, the result should output like
As you see, we can debug Dapr
applications with Visual Studio smoothly, it still a Dapr
application, can communicate with other Dapr
applications, but it is intercepted by tye
tool. Brilliant, right?
- OS
Windows 10
- Dapr
$ dapr --version
CLI version: 0.5.0
Runtime version: 0.5.0
- Tye
$ tye --version
0.1.0-alpha.20179.5+4f73950de52831e655463851ada7ae366f95b28c
You need to have Docker for Desktop on your machine to get starting.
Dapr - https://github.com/dapr/docs/tree/master/getting-started
Tye - https://github.com/dotnet/tye/blob/master/docs/getting_started.md
I hope you like this hacking and happy coding. Don't believe what I said, try it!
Source code of our project is at https://github.com/thangchung/practical-dapr/tree/v0.0.1
Thank you for your reading!
Top comments (0)