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
@@ -3,7 +3,7 @@ title: "Create your first C# durable function running in the isolated worker"
3
3
description: Create and publish a C# Azure Durable Function running in the isolated worker using Visual Studio or Visual Studio Code.
4
4
author: lilyjma
5
5
ms.topic: quickstart
6
-
ms.date: 01/31/2023
6
+
ms.date: 06/05/2024
7
7
ms.author: azfuncdf
8
8
zone_pivot_groups: code-editors-set-one
9
9
ms.devlang: csharp
@@ -60,79 +60,28 @@ In this section, you use Visual Studio Code to create a local Azure Functions pr
60
60
| ------ | ----- | ----------- |
61
61
| Select a language for your function app project | C# | Create a local C# Functions project. |
62
62
| Select a version | Azure Functions v4 | You only see this option when the Core Tools aren't already installed. In this case, Core Tools are installed the first time you run the app. |
63
-
| Select a .NET runtime | .NET 7.0 isolated | Creates a function project that supports .NET 7 running in isolated worker process and the Azure Functions Runtime 4.0. For more information, see [How to target Azure Functions runtime version](../functions-versions.md). |
64
-
| Select a template for your project's first function | Skip for now ||
63
+
| Select a .NET runtime | .NET 8.0 isolated | Creates a function project that supports .NET 8 running in isolated worker process and the Azure Functions Runtime 4.0. For more information, see [How to target Azure Functions runtime version](../functions-versions.md). |
64
+
| Select a template for your project's first function | Durable Functions Orchestration | Create a Durable Functions orchestration |
65
+
| Choose a durable storage type | Azure Storage | The default storage provider for Durable Functions. See [Durable Functions storage providers](./durable-functions-storage-providers.md) for more details. |
66
+
| Provide a function name | HelloOrchestration | Name of the orchestration function |
67
+
| Provide a namespace | Company.Function | Namespace for the generated class |
65
68
| Select how you would like to open your project | Open in current window | Reopens Visual Studio Code in the folder you selected. |
66
69
67
-
Visual Studio Code installs the Azure Functions Core Tools if needed. It also creates a function app project in a folder. This project contains the [host.json](../functions-host-json.md) and [local.settings.json](../functions-develop-local.md#local-settings-file) configuration files.
70
+
Visual Studio Code installs the Azure Functions Core Tools if needed. It also creates a function app project in a folder. This project contains the [host.json](../functions-host-json.md) and [local.settings.json](../functions-develop-local.md#local-settings-file) configuration files.
68
71
69
-
## Add NuGet package references
72
+
There's also a file called *HelloOrchestration.cs*, which contains the basic building blocks of a Durable Functions app:
|**`HelloCities`**| Manages the durable orchestration. In this case, the orchestration starts, creates a list, and adds the result of three functions calls to the list. When the three function calls are complete, it returns the list. |
130
-
|**`SayHello`**| The function returns a hello. It's the function that contains the business logic that is being orchestrated. |
131
-
|**`StartHelloCities`**| An [HTTP-triggered function](../functions-bindings-http-webhook.md) that starts an instance of the orchestration and returns a check status response. |
76
+
|**`HelloOrchestration`**| Defines the durable orchestration. In this case, the orchestration starts, creates a list, and adds the result of three functions calls to the list. When the three function calls are complete, it returns the list. |
77
+
|**`SayHello`**| Simple function returning hello. It's the function containing the business logic that is being orchestrated. |
78
+
|**`HelloOrchestration_HttpStart`**| An [HTTP-triggered function](../functions-bindings-http-webhook.md) that starts an instance of the orchestration and returns a check status response. |
79
+
80
+
You can find more details about these functions in [Durable Functions types and features](./durable-functions-types-features-overview.md).
132
81
133
82
## Configure storage
134
83
135
-
Your app needs a storage for runtime information. To use [Azurite](../../storage/common/storage-use-azurite.md?tabs=visual-studio-code), which is an emulator for Azure Storage, set`AzureWebJobStorage` in _local.settings.json_ to `UseDevelopmentStorage=true`:
84
+
You can use [Azurite](../../storage/common/storage-use-azurite.md?tabs=visual-studio-code), which is an emulator for Azure Storage, to test the function locally. Do this by setting`AzureWebJobStorage` in _local.settings.json_ to `UseDevelopmentStorage=true`:
136
85
137
86
```json
138
87
{
@@ -154,23 +103,25 @@ Azure Functions Core Tools lets you run an Azure Functions project locally. You'
154
103
155
104
1. To test your function, set a breakpoint in the `SayHello` activity function code and press <kbd>F5</kbd> to start the function app project. Output from Core Tools is displayed in the **Terminal** panel.
156
105
157
-
> [!NOTE]
158
-
> For more information on debugging, see [Durable Functions Diagnostics](durable-functions-diagnostics.md#debugging).
106
+
> [!NOTE]
107
+
> For more information on debugging, see [Durable Functions Diagnostics](durable-functions-diagnostics.md#debugging).
159
108
160
-
> [!NOTE]
161
-
> If you encounter a "No job functions found" error, please [update your Azure Functions Core Tools installation to the latest version](./../functions-core-tools-reference.md). Older versions of core tools do not support .NET isolated.
109
+
> [!NOTE]
110
+
> If you encounter a "No job functions found" error, please [update your Azure Functions Core Tools installation to the latest version](./../functions-core-tools-reference.md). Older versions of core tools do not support .NET isolated.
162
111
163
112
1. In the **Terminal** panel, copy the URL endpoint of your HTTP-triggered function.
164
113
165
114
:::image type="content" source="media/durable-functions-create-first-csharp/isolated-functions-vscode-debugging.png" alt-text="Screenshot of Azure local output window.":::
166
115
167
116
1. Use a tool like [Postman](https://www.getpostman.com/) or [cURL](https://curl.haxx.se/), and then send an HTTP POST request to the URL endpoint.
168
117
169
-
The response is the HTTP function's initial result, letting us know that the durable orchestration has started successfully. It isn't yet the end result of the orchestration. The response includes a few useful URLs. For now, let's query the status of the orchestration.
118
+
The response is the HTTP function's initial result, letting us know that the durable orchestration has started successfully. It isn't yet the end result of the orchestration. The response includes a few useful URLs.
170
119
171
-
1. Copy the URL value for `statusQueryGetUri`, paste it into the browser's address bar, and execute the request. Alternatively, you can also continue to use Postman to issue the GET request.
120
+
At this point, your breakpoint in the activity function should be hit because the orchestration has started. Step through it to get a response for the status of the orchestration.
172
121
173
-
The request will query the orchestration instance for the status. You must get an eventual response, which shows us that the instance has completed and includes the outputs or results of the durable function. It looks like:
122
+
1. Copy the URL value for `statusQueryGetUri`, paste it into the browser's address bar, and execute the request. Alternatively, you can also continue to use Postman to issue the GET request.
123
+
124
+
The request will query the orchestration instance for the status. You should see that the instance has completed and includes the outputs or results of the durable function. It looks like:
174
125
175
126
```json
176
127
{
@@ -184,6 +135,9 @@ Azure Functions Core Tools lets you run an Azure Functions project locally. You'
184
135
"lastUpdatedTime":"2023-01-31T18:48:56Z"
185
136
}
186
137
```
138
+
139
+
> [!NOTE]
140
+
> You can observe the [replay behavior](./durable-functions-orchestrations.md#reliability) of Durable Functions through breakpoints. Because this is an important concept to understand, it's highly recommended that you read the linked article.
187
141
188
142
1. To stop debugging, press <kbd>Shift + F5</kbd> in Visual Studio Code.
189
143
@@ -244,85 +198,35 @@ The Azure Functions template creates a project that can be published to a functi
| **Functions worker** | .NET 7 Isolated | Creates a function project that supports .NET 7 running in isolated worker process and the Azure Functions Runtime 4.0. For more information, see [How to target Azure Functions runtime version](../functions-versions.md). |
248
-
| **Function** | Empty | Creates an empty function app. |
249
-
| **Storage account** | Storage Emulator | A storage account is required for durable function state management. |
250
-
251
-
5. Select **Create** to create an empty function project. This project has the basic configuration files needed to run your functions. Make sure the box for _"Use Azurite for runtime storage account (AzureWebJobStorage)"_ is checked. This will use Azurite emulator.
201
+
| **Functions worker** | .NET 8 Isolated (Long Term Support) | Creates a function project that supports .NET 8 running in isolated worker process and the Azure Functions Runtime 4.0. For more information, see [How to target Azure Functions runtime version](../functions-versions.md). |
Note that there are other storage options you can use for your Durable Functions app. See [Durable Functions storage providers](durable-functions-storage-providers.md) to learn more about different storage options and what benefits they provide.
The most basic Durable Functions app contains the following three functions. Add them to a new class in the app:
204
+
> [!NOTE]
205
+
> If you don't see .NET 8 isolated in the Functions worker drop-down, it could be because you don't have the latest Azure Functions toolsets and templates. Go to Tools -> Options -> Projects and Solutions -> Azure Functions -> Check for updates to download the latest.
270
206
271
-
```csharp
272
-
usingMicrosoft.Azure.Functions.Worker.Http;
273
-
usingMicrosoft.Azure.Functions.Worker;
274
-
usingMicrosoft.DurableTask;
275
-
usingMicrosoft.DurableTask.Client;
276
-
usingMicrosoft.Extensions.Logging;
207
+
5. Make sure the box for _"Use Azurite for runtime storage account (AzureWebJobStorage)"_ is checked. This will use Azurite emulator. Select **Create** to create a function project with a Durable Functions orchestration template. This project has the basic configuration files needed to run your functions.
logger.LogInformation("Created new orchestration with instance ID = {instanceId}", instanceId);
209
+
> [!NOTE]
210
+
> There are other storage options you can use for your Durable Functions app. See [Durable Functions storage providers](durable-functions-storage-providers.md) to learn more about different storage options and what benefits they provide.
In your function app, you'll see a file called *Function1.cs* containing three functions, which are the basic building blocks of a Durable Functions:
312
213
313
-
```
314
214
| Method | Description |
315
215
| ----- | ----------- |
316
-
|**`HelloCities`**|Manages the durable orchestration. In this case, the orchestration starts, creates a list, and adds the result of three functions calls to the list. When the three function calls are complete, it returns the list. |
216
+
| **`RunOrchestrator`** | Defines the durable orchestration. In this case, the orchestration starts, creates a list, and adds the result of three functions calls to the list. When the three function calls are complete, it returns the list. |
317
217
| **`SayHello`** | The function returns a hello. It's the function that contains the business logic that is being orchestrated. |
318
-
|**`StartHelloCities`**| An [HTTP-triggered function](../functions-bindings-http-webhook.md) that starts an instance of the orchestration and returns a check status response. |
218
+
| **`HttpStart`** | An [HTTP-triggered function](../functions-bindings-http-webhook.md) that starts an instance of the orchestration and returns a check status response. |
319
219
220
+
You can find more details about these functions in [Durable Functions types and features](./durable-functions-types-features-overview.md).
320
221
321
222
## Test the function locally
322
223
323
224
Azure Functions Core Tools lets you run an Azure Functions project on your local development computer. You're prompted to install these tools the first time you start a function from Visual Studio.
324
225
325
-
1. To test your function, press <kbd>F5</kbd>. If prompted, accept the request from Visual Studio to download and install Azure Functions Core (CLI) tools. You may also need to enable a firewall exception so that the tools can handle HTTP requests.
226
+
1. To test your function, set a breakpoint in the `SayHello` activity function code and press <kbd>F5</kbd>. If prompted, accept the request from Visual Studio to download and install Azure Functions Core (CLI) tools. You may also need to enable a firewall exception so that the tools can handle HTTP requests.
227
+
228
+
> [!NOTE]
229
+
> For more information on debugging, see [Durable Functions Diagnostics](durable-functions-diagnostics.md#debugging).
326
230
327
231
2. Copy the URL of your function from the Azure Functions runtime output.
328
232
@@ -332,11 +236,13 @@ Azure Functions Core Tools lets you run an Azure Functions project on your local
332
236
333
237
:::image type="content" source="./media/durable-functions-create-first-csharp/isolated-functions-vs-status.png" alt-text="Screenshot of the browser window with statusQueryGetUri called out.":::
334
238
335
-
The response is the HTTP function's initial result, letting us know that the durable orchestration has started successfully. It isn't yet the end result of the orchestration. The response includes a few useful URLs. For now, let's query the status of the orchestration.
239
+
The response is the HTTP function's initial result, letting us know that the durable orchestration has started successfully. It isn't yet the end result of the orchestration. The response includes a few useful URLs.
240
+
241
+
At this point, your breakpoint in the activity function should be hit because the orchestration has started. Step through it to get a response for the status of the orchestration.
336
242
337
243
4. Copy the URL value for `statusQueryGetUri`, paste it into the browser's address bar, and execute the request.
338
244
339
-
The request will query the orchestration instance for the status. You must get an eventual response that looks like the following. This output shows us the instance has completed and includes the outputs or results of the durable function.
245
+
The request will query the orchestration instance for the status. You should see that the instance has completed and includes the outputs of your activity invocations. It looks like:
340
246
341
247
```json
342
248
{
@@ -351,6 +257,9 @@ Azure Functions Core Tools lets you run an Azure Functions project on your local
351
257
}
352
258
```
353
259
260
+
> [!NOTE]
261
+
> You can observe the [replay behavior](./durable-functions-orchestrations.md#reliability) of Durable Functions through breakpoints. Because this is an important concept to understand, it's highly recommended that you read the linked article.
262
+
354
263
5. To stop debugging, press <kbd>Shift + F5</kbd>.
355
264
356
265
After you've verified that the function runs correctly on your local computer, it's time to publish the project to Azure.
0 commit comments