You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this module, we will start by creating the first microservice named `ACA Web API – Backend` as illustrated in the [architecture diagram](../../assets/images/00-workshop-intro/ACA-Architecture-workshop.jpg). Followed by that we will provision the Azure resources needed to deploy the service to Azure Container Apps using the Azure CLI.
# Module 2 - Communication between Microservices in ACA
5
+
# Module 2 - Communication Between Microservices in ACA
6
+
!!! info "Module Duration"
7
+
60 minutes
6
8
7
9
In this module, we will add a service named `ACA Web API – Frontend` as illustrated in the [architecture diagram](../../assets/images/00-workshop-intro/ACA-Architecture-workshop.jpg). This service will host a simple ASP.NET Razor pages web app which allows the end users to manage their tasks. After that we will provision Azure resources needed to deploy the service to ACA using Azure CLI.
8
-
### 1. Create the frontend Web App project (Web APP)
10
+
### 1. Create the Frontend Web App project (Web APP)
9
11
10
12
- Open a command-line terminal and navigate to root folder of your project. Create a new folder as shown below:
In this module, we will start integrating Dapr into both services and see how Dapr with ACA will simplify complex microservices scenarios such as service discovery, service-to-service invocation, calling services asynchronously via pub/sub patterns, auto-scaling for overloaded services, etc..
8
10
9
-
### Benefits of integrating Dapr in Azure Container Apps
11
+
### Benefits of Integrating Dapr in Azure Container Apps
10
12
11
13
The Tasks Tracker microservice application is composed of multiple microservices (2 microservices so far), and function calls are spread across the network. To support the distributed nature of microservices,
12
14
we need to account for failures, retries, and timeouts. While Container Apps features the building blocks for running microservices, the use of Dapr provides an even richer microservices programming model.
@@ -22,10 +24,10 @@ Although we won't tap into all these benefits in this workshop its worth keeping
22
24
- Control what operations clients can do using access control policies.
23
25
- Capture traces and metrics for all calls between services to provide insights and diagnostics.
24
26
25
-
### Configure Dapr on a local development machine
27
+
### Configure Dapr on a Local Development Machine
26
28
In order to run applications using Dapr, we need to install and initialize Dapr CLI locally. The official documentation is quite clear, and we can follow the steps needed to [install](https://docs.dapr.io/getting-started/install-dapr-cli/) Dapr and then [Initialize](https://docs.dapr.io/getting-started/install-dapr-selfhost/) it.
27
29
28
-
### Run Backend API and Frontend Web App locally using Dapr
30
+
### Run Backend API and Frontend Web App Locally Using Dapr
29
31
You are now ready to run the applications locally using Dapr sidecar in a self-hosted mode. There is a VS code extension called [Dapr](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-dapr) which will allow you to run, debug, and interact with Dapr-enabled applications in VS Code.
30
32
31
33
- Let's start by running the Backend Web API service using Dapr. From VS Code open a new PowerShell terminal, run the below commands in PS terminal based on your .NET version.
# Module 4 - ACA State Store With Dapr State Management API
6
+
!!! info "Module Duration"
7
+
60 minutes
6
8
7
9
In this module we will switch the in-memory store of tasks and use a key/value persistent store (Azure Cosmos DB). By using the [Dapr State Management Building Block](https://docs.dapr.io/developing-applications/building-blocks/state-management/state-management-overview/), we will see how we can store the data in Azure Cosmos DB without installing any Cosmos DB SDK or write specific code to integrate our Backend API with Azure Cosmos DB.
8
10
Moreover, we will use Redis to store tasks when we are running the application locally. You will see that we can switch between different stores without any code changes, thanks to the [Dapr pluggable state stores feature](https://docs.dapr.io/developing-applications/building-blocks/state-management/state-management-overview/#pluggable-state-stores). It is a matter of adding new Dapr Component files and the underlying store will be changed. This page shows the [supported state stores](https://docs.dapr.io/reference/components-reference/supported-state-stores/) in Dapr.
@@ -11,7 +13,7 @@ Moreover, we will use Redis to store tasks when we are running the application l
11
13
12
14
### Overview of Dapr State Management API
13
15
14
-
Dapr's state management API allows you to save, read, and query key/value pairs in the supported state stores. To try this out and without doing any code changes or installing any NuGet packages we can directly invoke the State Management API and store the data on Redis locally. When you initialized Dapr in your local development environment, it installed Redis container instance locally. So we can use Redis locally to store and retrieve state. If you navigate to the path `%USERPROFILE%\.dapr\components` you will find a file named `statestore.yaml`. Inside this file, you will see the properties needed to access the local Redis instance. The [state store template component file structure](https://docs.dapr.io/operations/components/setup-state-store/) can be found on this link.
16
+
Dapr's state management API allows you to save, read, and query key/value pairs in the supported state stores. To try this out and without doing any code changes or installing any NuGet packages we can directly invoke the State Management API and store the data on Redis locally. When you initialized Dapr in your local development environment, it installed Redis container instance locally. So we can use Redis locally to store and retrieve state. If you navigate to the path `%USERPROFILE%\.dapr\components (assuming you are using windows)` you will find a file named `statestore.yaml`. Inside this file, you will see the properties needed to access the local Redis instance. The [state store template component file structure](https://docs.dapr.io/operations/components/setup-state-store/) can be found on this link.
15
17
16
18
To try out the State Management APIs, run the Backend API from VS Code by running the following command. Remember to replace the place holders with your own values:
17
19
@@ -102,11 +104,11 @@ For example if you execute the following GET [http://localhost:3500/v1.0/state/s
102
104
}
103
105
```
104
106
105
-
### Use Dapr Client SDK for State Store Management
107
+
### Use Dapr Client SDK For State Store Management
106
108
107
109
Whereas in the previous section we demonstrated using Dapr State Store without code changes, we will now introduce a change on the Backend API and create a new service named `TasksStoreManager.cs` which will implement the interface `ITasksManager.cs` to start storing tasks data on the persist store. Locally we will start testing with Redis, then we are going to change the state store to use Azure Cosmos DB.
108
110
109
-
#### 1. Add Dapr Client SDK to the Backend API
111
+
#### 1. Add Dapr Client SDK to The Backend API
110
112
111
113
Similar to what we have done in the Frontend Web App, we need to use Dapr Client SDK to manage the state store. Update below file with highlighted lines:
112
114
@@ -119,7 +121,7 @@ Similar to what we have done in the Frontend Web App, we need to use Dapr Client
119
121
</ItemGroup>
120
122
```
121
123
122
-
#### 2. Create a new concrete implementation to manage tasks persistence
124
+
#### 2. Create a New Concrete Implementation to Manage Tasks Persistence
123
125
124
126
As you recall from the previous module, we were storing the tasks in memory. Now we need to store them in Redis and later on Azure Cosmos DB.
125
127
The key thing to keep in mind here is that switching from redis to Azure Cosmos DB won't require changing the code below which is a huge advantage of using Dapr.
@@ -139,7 +141,7 @@ Add below file under the folder named **Services**. This file will implement the
139
141
The query API will not work against the local Redis store as you need to install [RediSearch](https://redis.io/docs/stack/search/) locally on your machine which is out of the scope for this workshop.
140
142
It will work locally once we switch to Azure Cosmos DB.
141
143
142
-
#### 3. Register the TasksStoreManager new service and DaprClient
144
+
#### 3. Register the TasksStoreManager New Service and DaprClient
143
145
144
146
Now we need to register the new service named `TasksStoreManager` and `DaprClient` when the Backend API app starts up. Update the below file with the highlighted text as shown below.
145
147
@@ -216,7 +218,7 @@ az cosmosdb keys list `
216
218
--resource-group $RESOURCE_GROUP
217
219
```
218
220
219
-
**2. Create a Component file for State Store Management:** Dapr uses a modular design where functionality is delivered as a component. Each component has an interface definition.
221
+
**2. Create a Component File for State Store Management:** Dapr uses a modular design where functionality is delivered as a component. Each component has an interface definition.
220
222
All the components are pluggable so that you can swap out one component with the same interface for another
221
223
222
224
Components are configured at design-time with a YAML file which is stored in either a components/local folder within your solution, or globally in the `.dapr` folder created when invoking `dapr init`.
@@ -331,7 +333,7 @@ Keep a note of the property `principalId` as we are going to use it in the next
331
333
}
332
334
```
333
335
334
-
#### 2. Assign the container app system-identity to the built-in Cosmos DB role
336
+
#### 2. Assign the Container App System-Identity To the Built-in Cosmos DB Role
335
337
336
338
Next, we need to associate the container app system-identity with the target Cosmos DB resource.
337
339
You can read more about Azure built-in roles for Cosmos DB or how to create custom fine-tuned roles [here](https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-setup-rbac#built-in-role-definitions).
@@ -361,7 +363,7 @@ We have to create a [dapr component schema file](https://learn.microsoft.com/en-
361
363
Azure Container Apps. Reason for this variance is that ACA Dapr schema is slightly simplified to support Dapr components and removes unnecessary fields, including `apiVersion`, `kind`, and redundant metadata and
362
364
spec properties.
363
365
364
-
#### 1. Create an ACA-Dapr Component file for State Store Management
366
+
#### 1. Create an ACA-Dapr Component File For State Store Management
365
367
366
368
Here it is recommended to separate the component files that will be used when deploying to Azure Container Apps from the ones which we will use when running our application locally (Dapr self-hosted).
367
369
@@ -381,7 +383,7 @@ Create a new folder named **aca-components** under the directory **TasksTracker.
381
383
- We are not referencing any Cosmos DB Keys/Connection strings as the authentication between Dapr and Cosmos DB will be configured using Managed Identities.
382
384
- We are setting the `scopes` array value to `tasksmanager-backend-api` to ensure Cosmos DB component is loaded at runtime by only the appropriate container apps. In our case it will be needed only for the container apps with Dapr application IDs `tasksmanager-backend-api`. In future modules we are going to include another container app which needs to access Cosmos DB.
383
385
384
-
#### 2. Build Frontend Web App and Backend API App images and push them to ACR
386
+
#### 2. Build Frontend Web App and Backend API App Images and Push Them to ACR
385
387
386
388
As we have done previously we need to build and deploy both app images to ACR, so they are ready to be deployed to Azure Container Apps.
387
389
To do so, continue using the same PowerShell console and paste the code below (Make sure you are on the following directory **TasksTracker.ContainerApps**):
For a complete list of the supported Dapr sidecar configurations in Container Apps, you can refer to [this link](https://learn.microsoft.com/en-us/azure/container-apps/dapr-overview?tabs=bicep1%2Cyaml#dapr-enablement).
430
432
431
-
#### 5. Deploy new revisions of the Frontend Web App and Backend API to Container Apps
433
+
#### 5. Deploy New Revisions of the Frontend Web App and Backend API to Container Apps
432
434
433
435
The last thing we need to do here is to update both container apps and deploy the new images from ACR. To do so we need to run the commands found below.
varplainTextContent=$"Task '{taskModel.TaskName}' is assigned to you. Task should be completed by the end of: {taskModel.TaskDueDate.ToString("dd/MM/yyyy")}";
0 commit comments