title | description | ms.topic | ms.date | ms.custom | zone_pivot_groups |
---|---|---|---|---|---|
Azure Event Grid bindings for Azure Functions |
Understand how to handle Event Grid events in Azure Functions. |
reference |
03/04/2022 |
fasttrack-edit, devx-track-extended-java, devx-track-js, devx-track-python, devx-track-ts |
programming-languages-set-functions |
This reference shows how to connect to Azure Event Grid using Azure Functions triggers and bindings.
[!INCLUDE functions-event-grid-intro]
Action | Type |
---|---|
Run a function when an Event Grid event is dispatched | Trigger |
Sends an Event Grid event | Output binding |
Control the returned HTTP status code | HTTP endpoint |
::: zone pivot="programming-language-csharp"
The extension NuGet package you install depends on the C# mode you're using in your function app:
Functions execute in an isolated C# worker process. To learn more, see Guide for running C# Azure Functions in an isolated worker process.
[!INCLUDE functions-in-process-model-retirement-note]
Functions execute in the same process as the Functions host. To learn more, see Develop C# class library functions using Azure Functions.
In a variation of this model, Functions can be run using C# scripting, which is supported primarily for C# portal editing. To update existing binding extensions for C# script apps running in the portal without having to republish your function app, see Update your extensions.
The functionality of the extension varies depending on the extension version:
This section describes using a class library. For C# scripting, you would need to instead install the extension bundle, version 3.x.
This version of the extension supports updated Event Grid binding parameter types of Azure.Messaging.CloudEvent and Azure.Messaging.EventGrid.EventGridEvent.
Add this version of the extension to your project by installing the NuGet package, version 3.x.
This section describes using a class library. For C# scripting, you would need to instead install the extension bundle, version 2.x.
Supports the default Event Grid binding parameter type of Microsoft.Azure.EventGrid.Models.EventGridEvent. Event Grid extension versions earlier than 3.x don't support CloudEvents schema. To consume this schema, instead use an HTTP trigger, or switch to Extension v3.x.
Add the extension to your project by installing the NuGet package, version 2.x.
[!INCLUDE functions-runtime-1x-retirement-note]
Functions 1.x apps automatically have a reference to the Microsoft.Azure.WebJobs NuGet package, version 2.x. Event Grid extension versions earlier than 3.x don't support CloudEvents schema. To consume this schema, instead use an HTTP trigger, or switch to Extension v3.x. To do so, you will need to upgrade your application to Functions 4.x.
The Event Grid output binding is only available for Functions 2.x and higher.
Add the extension to your project by installing the NuGet package, version 3.x.
Add the extension to your project by installing the NuGet package, version 2.x. Event Grid extension versions earlier than 3.x don't support CloudEvents schema. To consume this schema, instead use an HTTP trigger.
Functions version 1.x doesn't support the isolated worker process.
The Event Grid output binding is only available for Functions 2.x and higher.
::: zone-end
::: zone pivot="programming-language-javascript,programming-language-typescript,programming-language-python,programming-language-java,programming-language-powershell"
The Event Grid extension is part of an extension bundle, which is specified in your host.json project file. You may need to modify this bundle to change the version of the Event Grid binding, or if bundles aren't already installed. To learn more, see extension bundle.
You can add this version of the extension from the extension bundle v3 by adding or replacing the following configuration in your host.json
file:
[!INCLUDE functions-extension-bundles-json-v3]
To learn more, see Update your extensions.
You can install this version of the extension in your function app by registering the extension bundle, version 2.x. Event Grid extension versions earlier than 3.x don't support CloudEvents schema. To consume this schema, instead use an HTTP trigger.
The Event Grid output binding is only available for Functions 2.x and higher. Event Grid extension versions earlier than 3.x don't support CloudEvents schema. To consume this schema, instead use an HTTP trigger.
::: zone-end
::: zone pivot="programming-language-csharp"
The binding types supported for .NET depend on both the extension version and C# execution mode, which can be one of the following:
An isolated worker process class library compiled C# function runs in a process isolated from the runtime.
An in-process class library is a compiled C# function runs in the same process as the Functions runtime.
Choose a version to see binding type details for the mode and version.
The Event Grid extension supports parameter types according to the table below.
Binding | Parameter types |
---|---|
Event Grid trigger | CloudEvent EventGridEvent BinaryData Newtonsoft.Json.Linq.JObject string |
Event Grid output (single event) | CloudEvent EventGridEvent BinaryData Newtonsoft.Json.Linq.JObject string |
Event Grid output (multiple events) | ICollector<T> or IAsyncCollector<T> where T is one of the single event types |
This version of the extension supports parameter types according to the table below. It doesn't support for the CloudEvents schema, which is exclusive to Extension v3.x.
Binding | Parameter types |
---|---|
Event Grid trigger | Microsoft.Azure.EventGrid.Models.EventGridEvent Newtonsoft.Json.Linq.JObject string |
Event Grid output | Microsoft.Azure.EventGrid.Models.EventGridEvent Newtonsoft.Json.Linq.JObject string |
This version of the extension supports parameter types according to the table below. It doesn't support for the CloudEvents schema, which is exclusive to Extension v3.x.
Binding | Parameter types |
---|---|
Event Grid trigger | Newtonsoft.Json.Linq.JObjectstring |
Event Grid output | Newtonsoft.Json.Linq.JObjectstring |
The isolated worker process supports parameter types according to the tables below. Support for binding to Stream
, and to types from Azure.Messaging is in preview.
Event Grid trigger
[!INCLUDE functions-bindings-event-grid-trigger-dotnet-isolated-types]
Event Grid output binding
[!INCLUDE functions-bindings-event-grid-output-dotnet-isolated-types]
Earlier versions of this extension in the isolated worker process only support binding to strings and plain-old CLR object (POCO) types. Additional options are available to Extension v3.x.
Functions version 1.x doesn't support isolated worker process. To use the isolated worker model, upgrade your application to Functions 4.x.
:::zone-end
The Event Grid trigger uses a webhook HTTP request, which can be configured using the same host.json settings as the HTTP Trigger.
- If you have questions, submit an issue to the team here
- Event Grid trigger
- Event Grid output binding
- Run a function when an Event Grid event is dispatched
- Dispatch an Event Grid event