Skip to content

Commit 046c112

Browse files
author
Jill Grant
authored
Merge pull request #277849 from lilyjma/net-isolated-qs
Update Durable Functions .NET isolated quickstart
2 parents 5ba84b7 + d7eebf8 commit 046c112

File tree

1 file changed

+48
-139
lines changed

1 file changed

+48
-139
lines changed

articles/azure-functions/durable/durable-functions-isolated-create-first-csharp.md

Lines changed: 48 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Create your first C# durable function running in the isolated worker"
33
description: Create and publish a C# Azure Durable Function running in the isolated worker using Visual Studio or Visual Studio Code.
44
author: lilyjma
55
ms.topic: quickstart
6-
ms.date: 01/31/2023
6+
ms.date: 06/05/2024
77
ms.author: azfuncdf
88
zone_pivot_groups: code-editors-set-one
99
ms.devlang: csharp
@@ -60,79 +60,28 @@ In this section, you use Visual Studio Code to create a local Azure Functions pr
6060
| ------ | ----- | ----------- |
6161
| Select a language for your function app project | C# | Create a local C# Functions project. |
6262
| 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 |
6568
| Select how you would like to open your project | Open in current window | Reopens Visual Studio Code in the folder you selected. |
6669

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.
6871

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:
7073

71-
Add the following to your app project:
72-
73-
```xml
74-
<ItemGroup>
75-
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
76-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.1" />
77-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
78-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" OutputItemType="Analyzer" />
79-
</ItemGroup>
80-
```
81-
## Add functions to the app
82-
83-
The most basic Durable Functions app contains the following three functions. Add them to a new class in the app:
84-
85-
```csharp
86-
using Microsoft.Azure.Functions.Worker.Http;
87-
using Microsoft.Azure.Functions.Worker;
88-
using Microsoft.DurableTask;
89-
using Microsoft.DurableTask.Client;
90-
using Microsoft.Extensions.Logging;
91-
92-
static class HelloSequence
93-
{
94-
[Function(nameof(HelloCities))]
95-
public static async Task<string> HelloCities([OrchestrationTrigger] TaskOrchestrationContext context)
96-
{
97-
string result = "";
98-
result += await context.CallActivityAsync<string>(nameof(SayHello), "Tokyo") + " ";
99-
result += await context.CallActivityAsync<string>(nameof(SayHello), "London") + " ";
100-
result += await context.CallActivityAsync<string>(nameof(SayHello), "Seattle");
101-
return result;
102-
}
103-
104-
[Function(nameof(SayHello))]
105-
public static string SayHello([ActivityTrigger] string cityName, FunctionContext executionContext)
106-
{
107-
ILogger logger = executionContext.GetLogger(nameof(SayHello));
108-
logger.LogInformation("Saying hello to {name}", cityName);
109-
return $"Hello, {cityName}!";
110-
}
111-
112-
[Function(nameof(StartHelloCities))]
113-
public static async Task<HttpResponseData> StartHelloCities(
114-
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
115-
[DurableClient] DurableTaskClient client,
116-
FunctionContext executionContext)
117-
{
118-
ILogger logger = executionContext.GetLogger(nameof(StartHelloCities));
119-
120-
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(nameof(HelloCities));
121-
logger.LogInformation("Created new orchestration with instance ID = {instanceId}", instanceId);
122-
123-
return client.CreateCheckStatusResponse(req, instanceId);
124-
}
125-
}
126-
```
12774
| Method | Description |
12875
| ----- | ----------- |
129-
| **`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).
13281

13382
## Configure storage
13483

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`:
13685

13786
```json
13887
{
@@ -154,23 +103,25 @@ Azure Functions Core Tools lets you run an Azure Functions project locally. You'
154103

155104
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.
156105

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).
159108
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.
162111
163112
1. In the **Terminal** panel, copy the URL endpoint of your HTTP-triggered function.
164113

165114
:::image type="content" source="media/durable-functions-create-first-csharp/isolated-functions-vscode-debugging.png" alt-text="Screenshot of Azure local output window.":::
166115

167116
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.
168117

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.
170119

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.
172121

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:
174125

175126
```json
176127
{
@@ -184,6 +135,9 @@ Azure Functions Core Tools lets you run an Azure Functions project locally. You'
184135
"lastUpdatedTime":"2023-01-31T18:48:56Z"
185136
}
186137
```
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.
187141

188142
1. To stop debugging, press <kbd>Shift + F5</kbd> in Visual Studio Code.
189143

@@ -244,85 +198,35 @@ The Azure Functions template creates a project that can be published to a functi
244198

245199
| Setting | Suggested value | Description |
246200
| ------------ | ------- |----------------------------------------- |
247-
| **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). |
202+
| **Function** | Durable Functions Orchestration | Creates a Durable Functions orchestration. |
252203

253-
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.
254-
255-
## Add NuGet package references
256-
257-
Add the following to your app project:
258-
259-
```xml
260-
<ItemGroup>
261-
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
262-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.1" />
263-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
264-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" OutputItemType="Analyzer" />
265-
</ItemGroup>
266-
```
267-
## Add functions to the app
268-
269-
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.
270206

271-
```csharp
272-
using Microsoft.Azure.Functions.Worker.Http;
273-
using Microsoft.Azure.Functions.Worker;
274-
using Microsoft.DurableTask;
275-
using Microsoft.DurableTask.Client;
276-
using Microsoft.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.
277208

278-
static class HelloSequence
279-
{
280-
[Function(nameof(HelloCities))]
281-
public static async Task<string> HelloCities([OrchestrationTrigger] TaskOrchestrationContext context)
282-
{
283-
string result = "";
284-
result += await context.CallActivityAsync<string>(nameof(SayHello), "Tokyo") + " ";
285-
result += await context.CallActivityAsync<string>(nameof(SayHello), "London") + " ";
286-
result += await context.CallActivityAsync<string>(nameof(SayHello), "Seattle");
287-
return result;
288-
}
289-
290-
[Function(nameof(SayHello))]
291-
public static string SayHello([ActivityTrigger] string cityName, FunctionContext executionContext)
292-
{
293-
ILogger logger = executionContext.GetLogger(nameof(SayHello));
294-
logger.LogInformation("Saying hello to {name}", cityName);
295-
return $"Hello, {cityName}!";
296-
}
297-
298-
[Function(nameof(StartHelloCities))]
299-
public static async Task<HttpResponseData> StartHelloCities(
300-
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
301-
[DurableClient] DurableTaskClient client,
302-
FunctionContext executionContext)
303-
{
304-
ILogger logger = executionContext.GetLogger(nameof(StartHelloCities));
305-
306-
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(nameof(HelloCities));
307-
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.
308211

309-
return client.CreateCheckStatusResponse(req, instanceId);
310-
}
311-
}
212+
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:
312213

313-
```
314214
| Method | Description |
315215
| ----- | ----------- |
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. |
317217
| **`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. |
319219

220+
You can find more details about these functions in [Durable Functions types and features](./durable-functions-types-features-overview.md).
320221

321222
## Test the function locally
322223

323224
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.
324225

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).
326230

327231
2. Copy the URL of your function from the Azure Functions runtime output.
328232

@@ -332,11 +236,13 @@ Azure Functions Core Tools lets you run an Azure Functions project on your local
332236

333237
:::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.":::
334238

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.
336242

337243
4. Copy the URL value for `statusQueryGetUri`, paste it into the browser's address bar, and execute the request.
338244

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:
340246

341247
```json
342248
{
@@ -351,6 +257,9 @@ Azure Functions Core Tools lets you run an Azure Functions project on your local
351257
}
352258
```
353259

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+
354263
5. To stop debugging, press <kbd>Shift + F5</kbd>.
355264

356265
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

Comments
 (0)