This reference shows how to connect to Azure Event Grid using Azure Functions triggers and bindings.
Event Grid is an Azure service that sends HTTP requests to notify you about events that happen in publishers. A publisher is the service or resource that originates the event. For example, an Azure blob storage account is a publisher, and a blob upload or deletion is an event. Some Azure services have built-in support for publishing events to Event Grid.
Event handlers receive and process events. Azure Functions is one of several Azure services that have built-in support for handling Event Grid events. Functions provides an Event Grid trigger, which invokes a function when an event is received from Event Grid. A similar output binding can be used to send events from your function to an Event Grid custom topic.
You can also use an HTTP trigger to handle Event Grid Events. To learn more, see Receive events to an HTTP endpoint. We recommend using the Event Grid trigger over HTTP trigger.
Install extensionThe extension NuGet package you install depends on the C# mode you're using in your function app:
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.
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.
Install bundleThe 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:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.3.0, 4.0.0)"
}
}
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.
Binding typesThe 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.
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.
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.
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
When you want the function to process a single event, the Event Grid trigger can bind to the following types:
Type Description JSON serializable types Functions tries to deserialize the JSON data of the event into a plain-old CLR object (POCO) type.string
The event as a string. BinaryData1 The bytes of the event message. CloudEvent1 The event object. Use when Event Grid is configured to deliver using the CloudEvents schema. EventGridEvent1 The event object. Use when Event Grid is configured to deliver using the Event Grid schema.
When you want the function to process a batch of events, the Event Grid trigger can bind to the following types:
Type DescriptionCloudEvent[]
1,
EventGridEvent[]
1,
string[]
,
BinaryData[]
1 An array of events from the batch. Each entry represents one event.
1 To use these types, you need to reference Microsoft.Azure.Functions.Worker.Extensions.EventGrid 3.3.0 or later and the common dependencies for SDK type bindings.
Event Grid output binding
When you want the function to write a single event, the Event Grid output binding can bind to the following types:
Type Descriptionstring
The event as a string. byte[]
The bytes of the event message. JSON serializable types An object representing a JSON event. Functions tries to serialize a plain-old CLR object (POCO) type into JSON data.
When you want the function to write multiple events, the Event Grid output binding can bind to the following types:
Type DescriptionT[]
where T
is one of the single event types An array containing multiple events. Each entry represents one event.
For other output scenarios, create and use an EventGridPublisherClient with other types from Azure.Messaging.EventGrid directly. See Register Azure clients for an example of using dependency injection to create a client type from the Azure SDK.
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.
host.json settingsThe Event Grid trigger uses a webhook HTTP request, which can be configured using the same host.json settings as the HTTP Trigger.
Next stepsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4