0
0
Azurecloud~5 mins

Dapr integration overview in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Dapr helps apps talk to each other and use cloud features easily. It solves the problem of writing complex code to connect services by providing simple building blocks.
When you want your app to save state without writing database code.
When your app needs to send messages to other apps reliably.
When you want to call another service without worrying about network details.
When you want to run your app on Azure and use cloud features simply.
When you want to add features like pub/sub or secrets without changing your app much.
Config File - dapr-config.yaml
dapr-config.yaml
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: appconfig
spec:
  tracing:
    samplingRate: "1"
  mtls:
    enabled: true
  httpPipeline:
    handlers:
    - name: cors
      type: middleware.http.cors
      version: v1
      metadata:
      - name: allowedOrigins
        value: "*"
  features:
  - name: actors
    enabled: true

This file configures Dapr features for your app.

  • tracing: Enables tracing to see app calls.
  • mtls: Secures communication between services.
  • httpPipeline: Adds middleware like CORS for web requests.
  • features: Enables actors for stateful services.
Commands
This command installs and starts Dapr runtime locally on your machine to test apps with Dapr features.
Terminal
dapr init
Expected OutputExpected
Downloading binaries and setting up Dapr runtime... Dapr has been successfully initialized
Starts your app with Dapr sidecar. The sidecar listens on port 3500 and your app runs on port 5000. This lets your app use Dapr features via HTTP calls to the sidecar.
Terminal
dapr run --app-id myapp --app-port 5000 --dapr-http-port 3500 dotnet run
Expected OutputExpected
== APP == Now listening on: http://localhost:5000 == DAPR == Starting Dapr sidecar on HTTP port 3500
--app-id - Sets a unique name for your app in Dapr
--app-port - Specifies the port your app listens on
--dapr-http-port - Sets the port for Dapr sidecar HTTP API
This command asks Dapr sidecar to get state stored under 'mykey' from the configured state store. It shows how your app can use Dapr to save and retrieve data easily.
Terminal
curl http://localhost:3500/v1.0/state/statestore/mykey -X GET
Expected OutputExpected
"myvalue"
Key Concept

If you remember nothing else, remember: Dapr runs alongside your app as a helper that makes cloud features easy to use without changing your app code much.

Common Mistakes
Not running 'dapr init' before starting the app with Dapr.
Dapr runtime is not installed or started, so the sidecar cannot run and your app won't connect to Dapr features.
Always run 'dapr init' once before running apps with Dapr.
Using wrong ports or missing --app-port when running 'dapr run'.
Dapr sidecar cannot forward calls to your app if ports are incorrect, causing communication failures.
Specify correct --app-port matching your app's listening port.
Calling Dapr APIs directly on app port instead of Dapr sidecar port.
Dapr APIs are exposed on the sidecar port, not your app port, so calls fail or get no response.
Use the Dapr HTTP port (default 3500) to call Dapr APIs.
Summary
Run 'dapr init' to install and start Dapr runtime locally.
Use 'dapr run' with your app to start it alongside the Dapr sidecar.
Call Dapr APIs on the sidecar port to use features like state management.