Skip to content

Commit d7ec11f

Browse files
authored
Merge pull request #248926 from nzthiago/main
Adding .NET Isolated to event-based blob trigger tutorial.
2 parents f706cad + 96f6a11 commit d7ec11f

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

articles/azure-functions/functions-event-grid-blob-trigger.md

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: This tutorial shows how to create a low-latency, event-driven trigg
44
author: cachai2
55
ms.topic: tutorial
66
ms.custom: devx-track-extended-java, devx-track-js, devx-track-python
7-
ms.date: 3/1/2021
7+
ms.date: 8/22/2023
88
ms.author: cachai
99
zone_pivot_groups: programming-languages-set-functions-lang-workers
1010
#Customer intent: As an Azure Functions developer, I want learn how to create an Event Grid-based trigger on a Blob Storage container so that I can get a more rapid response to changes in the container.
@@ -88,7 +88,7 @@ When you create a Blob Storage-triggered function using Visual Studio Code, you
8888
|Prompt|Action|
8989
|--|--|
9090
|**Select a language**| Select `C#`. |
91-
|**Select a .NET runtime**| Select `.NET 6.0 LTS`. Event-driven blob triggers aren't yet supported when running in an isolated worker process. |
91+
|**Select a .NET runtime**| Select `.NET 6.0 Isolated LTS` for running in an [isolated worker process](dotnet-isolated-process-guide.md) or `.NET 6.0 LTS` for [in-process](functions-dotnet-class-library.md). |
9292
|**Select a template for your project's first function**| Select `Azure Blob Storage trigger`. |
9393
|**Provide a function name**| Enter `BlobTriggerEventGrid`. |
9494
|**Provide a namespace** | Enter `My.Functions`. |
@@ -156,27 +156,27 @@ To use the Event Grid-based Blob Storage trigger, your function requires at leas
156156
::: zone pivot="programming-language-csharp"
157157
To upgrade your project with the required extension version, in the Terminal window, run the following command: [dotnet add package](/dotnet/core/tools/dotnet-add-package)
158158

159-
<!---# [In-process](#tab/in-process) -->
159+
# [Isolated process](#tab/isolated-process)
160160
```bash
161-
dotnet add package Microsoft.Azure.WebJobs.Extensions.Storage --version 5.0.1
161+
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs --version 6.1.0
162162
```
163-
<!---# [Isolated process](#tab/isolated-process)
163+
# [In-process](#tab/in-process)
164164
```bash
165-
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Storage --version 5.0.0
165+
dotnet add package Microsoft.Azure.WebJobs.Extensions.Storage --version 5.1.3
166166
```
167167
---
168-
-->
168+
169169
::: zone-end
170170
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-python,programming-language-java"
171171

172172
1. Open the host.json project file, and inspect the `extensionBundle` element.
173173

174-
1. If `extensionBundle.version` isn't at least `3.3.0 `, replace `extensionBundle` with the following version:
174+
1. If `extensionBundle.version` isn't at least `3.3.0 `, replace `extensionBundle` with the latest:
175175

176176
```json
177177
"extensionBundle": {
178178
"id": "Microsoft.Azure.Functions.ExtensionBundle",
179-
"version": "[3.3.0, 4.0.0)"
179+
"version": "[4.0.0, 5.0.0)"
180180
}
181181
```
182182

@@ -186,14 +186,26 @@ dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Storage --version
186186

187187
::: zone pivot="programming-language-csharp"
188188
In the BlobTriggerEventGrid.cs file, add `Source = BlobTriggerSource.EventGrid` to the parameters for the Blob trigger attribute, for example:
189-
189+
190+
# [Isolated process](#tab/isolated-process)
191+
```csharp
192+
[Function("BlobTriggerCSharp")]
193+
public async Task Run([BlobTrigger("samples-workitems/{name}", Source = BlobTriggerSource.EventGrid, Connection = "<NAMED_STORAGE_CONNECTION>")] Stream myBlob, string name, FunctionContext executionContext)
194+
{
195+
var logger = executionContext.GetLogger("BlobTriggerCSharp");
196+
logger.LogInformation($"C# Blob trigger function Processed blob\n Name: {name} \n Size: {myBlob.Length} Bytes");
197+
}
198+
```
199+
# [In-process](#tab/in-process)
190200
```csharp
191201
[FunctionName("BlobTriggerCSharp")]
192202
public static void Run([BlobTrigger("samples-workitems/{name}", Source = BlobTriggerSource.EventGrid, Connection = "<NAMED_STORAGE_CONNECTION>")]Stream myBlob, string name, ILogger log)
193203
{
194204
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
195205
}
196206
```
207+
---
208+
197209
::: zone-end
198210
::: zone pivot="programming-language-python"
199211
After you create the function, in the function.json configuration file, add `"source": "EventGrid"` to the `myBlob` binding, for example:
@@ -270,10 +282,17 @@ Event Grid validates the endpoint URL when you create an event subscription in t
270282

271283
When your function runs locally, the default endpoint used for an event-driven blob storage trigger looks like the following URL:
272284

273-
::: zone pivot="programming-language-csharp"
285+
::: zone pivot="programming-language-csharp"
286+
# [Isolated process](#tab/isolated-process)
287+
```http
288+
http://localhost:7071/runtime/webhooks/blobs?functionName=Host.Functions.BlobTriggerEventGrid
289+
```
290+
# [In-process](#tab/in-process)
274291
```http
275292
http://localhost:7071/runtime/webhooks/blobs?functionName=BlobTriggerEventGrid
276293
```
294+
---
295+
277296
::: zone-end
278297
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-python,programming-language-java"
279298
```http
@@ -317,12 +336,17 @@ The endpoint used in the event subscription is made up of three different parts,
317336
| --- | --- |
318337
| Prefix and server name | When your function runs locally, the server name with an `https://` prefix comes from the **Forwarding** URL generated by *ngrok*. In the localhost URL, the *ngrok* URL replaces `http://localhost:7071`. When running in Azure, you'll instead use the published function app server, which is usually in the form `https://<FUNCTION_APP_NAME>.azurewebsites.net`. |
319338
| Path | The path portion of the endpoint URL comes from the localhost URL copied earlier, and looks like `/runtime/webhooks/blobs` for a Blob Storage trigger. The path for an Event Grid trigger would be `/runtime/webhooks/EventGrid` |
320-
| Query string | The `functionName=BlobTriggerEventGrid` parameter in the query string sets the name of the function that handles the event. For functions other than C#, the function name is qualified by `Host.Functions.`. If you used a different name for your function, you'll need to change this value. An access key isn't required when running locally. When running in Azure, you'll also need to include a `code=` parameter in the URL, which contains a key that you can get from the portal. |
339+
| Query string | For all languages including .NET Isolated the `functionName=Host.Functions.BlobTriggerEventGrid` parameter, except for .NET In-process which should be `functionName=BlobTriggerEventGrid` in the query string sets the name of the function that handles the event. If you used a different name for your function, you'll need to change this value. An access key isn't required when running locally. When running in Azure, you'll also need to include a `code=` parameter in the URL, which contains a key that you can get from the portal. |
321340

322341
The following screenshot shows an example of how the final endpoint URL should look when using a Blob Storage trigger named `BlobTriggerEventGrid`:
323342

324343
::: zone pivot="programming-language-csharp"
344+
# [Isolated process](#tab/isolated-process)
345+
![Endpoint selection](./media/functions-event-grid-blob-trigger/functions-event-grid-local-dev-event-subscription-endpoint-selection-qualified.png)
346+
# [In-process](#tab/in-process)
325347
![Endpoint selection](./media/functions-event-grid-blob-trigger/functions-event-grid-local-dev-event-subscription-endpoint-selection.png)
348+
---
349+
326350
::: zone-end
327351
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-python,programming-language-java"
328352
![Endpoint selection](./media/functions-event-grid-blob-trigger/functions-event-grid-local-dev-event-subscription-endpoint-selection-qualified.png)
@@ -368,7 +392,7 @@ An event subscription, powered by Azure Event Grid, raises events based on chang
368392
| **Name** | *myBlobLocalNgrokEventSub* | Name that identifies the event subscription. You can use the name to quickly find the event subscription. |
369393
| **Event Schema** | **Event Grid Schema** | Use the default schema for events. |
370394
| **System Topic Name** | *samples-workitems-blobs* | Name for the topic, which represents the container. The topic is created with the first subscription, and you'll use it for future event subscriptions. |
371-
| **Filter to Event Types** | *Blob Created*<br/>*Blob Deleted*|
395+
| **Filter to Event Types** | *Blob Created*|
372396
| **Endpoint Type** | **Web Hook** | The blob storage trigger uses a web hook endpoint. You would use Azure Functions for an Event Grid trigger. |
373397
| **Endpoint** | Your ngrok-based URL endpoint | Use the ngrok-based URL endpoint that you determined earlier. |
374398

@@ -449,9 +473,16 @@ You'll include this value in the query string of new endpoint URL.
449473
Create a new endpoint URL for the Blob Storage trigger based on the following example:
450474

451475
::: zone pivot="programming-language-csharp"
476+
# [Isolated process](#tab/isolated-process)
477+
```http
478+
https://<FUNCTION_APP_NAME>.azurewebsites.net/runtime/webhooks/blobs?functionName=Host.Functions.BlobTriggerEventGrid&code=<BLOB_EXTENSION_KEY>
479+
```
480+
# [In-process](#tab/in-process)
452481
```http
453482
https://<FUNCTION_APP_NAME>.azurewebsites.net/runtime/webhooks/blobs?functionName=BlobTriggerEventGrid&code=<BLOB_EXTENSION_KEY>
454483
```
484+
---
485+
455486
::: zone-end
456487
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-python,programming-language-java"
457488
```http
@@ -479,7 +510,7 @@ This time, you'll include the filter on the event subscription so that only JPEG
479510
| ------------ | ---------------- | ----------- |
480511
| **Name** | *myBlobAzureEventSub* | Name that identifies the event subscription. You can use the name to quickly find the event subscription. |
481512
| **Event Schema** | **Event Grid Schema** | Use the default schema for events. |
482-
| **Filter to Event Types** | *Blob Created*<br/>*Blob Deleted*|
513+
| **Filter to Event Types** | *Blob Created*|
483514
| **Endpoint Type** | **Web Hook** | The blob storage trigger uses a web hook endpoint. You would use Azure Functions for an Event Grid trigger. |
484515
| **Endpoint** | Your new Azure-based URL endpoint | Use the URL endpoint that you built, which includes the key value. |
485516

17.3 KB
Loading

includes/functions-bindings-csharp-intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ ms.author: glenga
88

99
A C# function can be created by using one of the following C# modes:
1010

11-
* [In-process class library](../articles/azure-functions/functions-dotnet-class-library.md): Compiled C# function that runs in the same process as the Functions runtime. In a variation of this model, Functions can be run using [C# scripting](../articles/azure-functions/functions-reference-csharp.md), which is supported primarily for C# portal editing. Extensions for in-process functions use `Microsoft.Azure.WebJobs.Extensions.*` namespaces.
1211
* [Isolated worker process class library](../articles/azure-functions/dotnet-isolated-process-guide.md): Compiled C# function that runs in a worker process that's isolated from the runtime. Isolated worker process is required to support C# functions running on LTS and non-LTS versions .NET and the .NET Framework. Extensions for isolated worker process functions use `Microsoft.Azure.Functions.Worker.Extensions.*` namespaces.
12+
* [In-process class library](../articles/azure-functions/functions-dotnet-class-library.md): Compiled C# function that runs in the same process as the Functions runtime. In a variation of this model, Functions can be run using [C# scripting](../articles/azure-functions/functions-reference-csharp.md), which is supported primarily for C# portal editing. Extensions for in-process functions use `Microsoft.Azure.WebJobs.Extensions.*` namespaces.

0 commit comments

Comments
 (0)