This repository contains a simple demo that shows how Dapr simplifies the implementation of polyglot microservices and how Dapr makes it possible to switch between different deployment environments without changing the application code.
The demo consists of three applications.
- Client: Written in Go, uses dapr service invocation to talk to the MessageService over GRPC.
- MessageService: Written in C# .NET 6, uses dapr state management to persist state and also uses the publish & subscribe building block to publish messages.
- NotificationService: Written in TypeScript / Node.js, uses the publish & subscribe building block to subscribe on messages from the MessageService and outputs them on the console.
The demo shows how Dapr enables polyglot microservices to run in different environments (e.g. local and cloud) without changing a line of application code. For this purpose, the demo uses different third-party components for each environment.
Third-party components used in local environments:
- Redis (State store and message broker)
- Zipkin (Distributed Tracing)
Third-party components used in cloud environments:
- Azure CosmosDB (State store)
- Azure Service Bus (Message broker)
- Azure Application Insights with OpenTelemetry collector (Distributed Tracing)
The Dapr components definitions for running the demo on Kubernetes are located in the /dapr/kubernetes/
directory.
Follow these steps to run the Dapr demo on Azure Kubernetes Service (AKS) using Azure services as third-party components.
To run the Dapr demo on Kubernetes in Azure, you need running instances of the following services.
- Azure Kubernetes Service with installed Dapr (Deploy Dapr on a Kubernetes cluster)
- Azure CosmosDB (Dapr Docs for Azure CosmosDB setup)
- Azure Service Bus (Dapr Docs for Azure Service Bus setup)
- Azure Application Insights (Dapr Docs on using Application Insights with OpenTelemetry Collector)
- kubectl
Additionally, you will need to create kubernetes secrets to connect to the Azure services. Set the required parameters as value. Refer to the Dapr Docs for details on connection parameters.
- Create a kubernetes secret named
cosmos-db-secrets
with the following keys:- url
- masterKey
- database
- collection
- Create a kubernetes secret named
servicebus-secrets
with the following key:- connectionString
- Configure the
instrumentation_key
in thedapr-demo-application-insights.yaml
file by replacing<REPLACE-WITH-INSTRUMENTATION-KEY>
with your Azure Application Insights instrumentation key. Be careful to not accidentally commit your instrumentation key!
Connect to your AKS cluster and switch kubectl context to your AKS cluster. Then run the following command.
kubectl apply -f ./dapr/kubernetes/cloud
Follow these steps to run the Dapr demo on a local Kubernetes cluster using local third-party components.
- Kubernetes with installed Dapr (Deploy Dapr on a Kubernetes cluster)
- Redis (Dapr Docs instructions for installing Redis in Kubernetes)
- kubectl
kubectl apply -f ./dapr/kubernetes/local
The Dapr components definitions for running the demo in self-hosted mode are located in the /dapr/self-hosted/
directory.
To run the Dapr demo in self-hosted mode using cloud components, you will need the following prerequisites:
- .NET 6.0
- Go
- Node.js with NPM
- Dapr
- Azure CosmosDB (Dapr Docs for Azure CosmosDB setup)
- Azure Service Bus (Dapr Docs for Azure Service Bus setup)
Rename the provided dapr-demo-secrets-store.json.example
file to dapr-demo-secrets-store.json
and fill in the parameters required to connect to the components.
Additionally, you will have to install the necessary npm packages of the notificationservice:
cd ./services/notificationservice
npm install
Start the services in the following order and wait until you see You're up and running! Both Dapr and your app logs will appear here.
as an output before starting the next service.
If you are on Windows or if you have PowerShell Core installed, you can use the run-notification-service.ps1
to start the application:
cd ./dapr/self-hosted/cloud
./run-notification-service.ps1
Otherwise, start the application using the dapr CLI:
cd ./services/notificationservice
dapr run `
--app-id dapr-demo-notification-service `
--app-port 5005 `
--components-path ../../dapr/self-hosted/cloud `
npm run start
If you are on Windows or if you have PowerShell Core installed, you can use the run-message-service.ps1
to start the application:
cd ./dapr/self-hosted/cloud
./run-message-service.ps1
Otherwise, start the application using the dapr cli:
cd ./services/messageservice
dapr run `
--app-id dapr-demo-message-service `
--app-port 5002 `
--app-protocol grpc `
--components-path ../../dapr/self-hosted/cloud `
dotnet run
If you are on Windows or if you have PowerShell Core installed, you can use the run-client.ps1
to start the application:
cd ./dapr/self-hosted/cloud
./run-client.ps1
Otherwise, start the application using the dapr CLI:
cd ./services/client
dapr run `
--app-id dapr-demo-client `
--components-path ../../dapr/self-hosted/cloud `
go run main.go
To run the Dapr demo in self-hosted mode using local components, you need the following prerequisites:
- .NET 6.0
- Go
- Node.js with NPM
- Dapr
- Redis (Automatically installed with Dapr)
Rename the provided dapr-demo-secrets-store.json.example
file to dapr-demo-secrets-store.json
and fill in the parameters required to connect to the components.
Additionally, you will have to install the necessary npm packages of the notificationservice:
cd ./services/notificationservice
npm install
Start the services in the following order and wait until you see You're up and running! Both Dapr and your app logs will appear here.
as an output before starting the next service.
If you are on Windows or if you have PowerShell Core installed, you can use the run-notification-service.ps1
to start the application:
cd ./dapr/self-hosted/local
./run-notification-service.ps1
Otherwise, start the application using the dapr cli:
cd ./services/notificationservice
dapr run `
--app-id dapr-demo-notification-service `
--app-port 5005 `
--components-path ../../dapr/self-hosted/local `
npm run start
If you are on Windows or if you have PowerShell Core installed, you can use the run-message-service.ps1
to start the application:
cd ./dapr/self-hosted/local
./run-message-service.ps1
Otherwise, start the application using the dapr CLI:
cd ./services/messageservice
dapr run `
--app-id dapr-demo-message-service `
--app-port 5002 `
--app-protocol grpc `
--components-path ../../dapr/self-hosted/local `
dotnet run
If you are on Windows or if you have PowerShell Core installed, you can use the run-client.ps1
to start the application:
cd ./dapr/self-hosted/local
./run-client.ps1
Otherwise, start the application using the dapr CLI:
cd ./services/client
dapr run `
--app-id dapr-demo-client `
--components-path ../../dapr/self-hosted/local `
go run main.go
If everything was setup up correctly, you should see the following output of the Notification Service with an increasing counter. The output is the same for all deployment variants.