Microsoft.Azure.WebJobs.Extensions.EventGrid
3.2.1
dotnet add package Microsoft.Azure.WebJobs.Extensions.EventGrid --version 3.2.1
NuGet\Install-Package Microsoft.Azure.WebJobs.Extensions.EventGrid -Version 3.2.1
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="3.2.1" />
paket add Microsoft.Azure.WebJobs.Extensions.EventGrid --version 3.2.1
#r "nuget: Microsoft.Azure.WebJobs.Extensions.EventGrid, 3.2.1"
// Install Microsoft.Azure.WebJobs.Extensions.EventGrid as a Cake Addin
#addin nuget:?package=Microsoft.Azure.WebJobs.Extensions.EventGrid&version=3.2.1
// Install Microsoft.Azure.WebJobs.Extensions.EventGrid as a Cake Tool
#tool nuget:?package=Microsoft.Azure.WebJobs.Extensions.EventGrid&version=3.2.1
Azure WebJobs EventGrid client library for .NET
This extension provides functionality for receiving Event Grid webhook calls in Azure Functions, allowing you to easily write functions that respond to any event published to Event Grid.
Getting started
Install the package
Install the Event Grid extension with NuGet:
dotnet add package Microsoft.Azure.WebJobs.Extensions.EventGrid
Prerequisites
You must have an Azure subscription and an Azure resource group with a custom Event Grid topic or domain. Follow this step-by-step tutorial to register the Event Grid resource provider and create Event Grid topics using the Azure portal. There is a similar tutorial using Azure CLI.
Authenticate the Client
In order for the extension publish events, you will need the endpoint
of the Event Grid topic and a credential
, which can be created using the topic's access key.
You can find the endpoint for your Event Grid topic either in the Azure Portal or by using the Azure CLI snippet below.
az eventgrid topic show --name <your-resource-name> --resource-group <your-resource-group-name> --query "endpoint"
The access key can also be found through the portal, or by using the Azure CLI snippet below:
az eventgrid topic key list --name <your-resource-name> --resource-group <your-resource-group-name> --query "key1"
Key concepts
Using Event Grid output binding
Please follow the binding tutorial to learn about using this extension for publishing EventGrid events.
Using Event Grid trigger
Please follow the tutorial to learn about triggering an Azure Function when an event is published.
Examples
Functions that uses Event Grid output binding
If you are using the EventGrid schema for your topic, you can output EventGridEvents.
public static class EventGridEventBindingFunction
{
[FunctionName("EventGridEventBindingFunction")]
public static async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
[EventGrid(TopicEndpointUri = "EventGridEndpoint", TopicKeySetting = "EventGridKey")] IAsyncCollector<EventGridEvent> eventCollector)
{
EventGridEvent e = new EventGridEvent(await req.ReadAsStringAsync(), "IncomingRequest", "IncomingRequest", "1.0.0");
await eventCollector.AddAsync(e);
return new OkResult();
}
}
If you are using the CloudEvent schema for your topic, you can output CloudEvents.
public static class CloudEventBindingFunction
{
[FunctionName("CloudEventBindingFunction")]
public static async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
[EventGrid(TopicEndpointUri = "EventGridEndpoint", TopicKeySetting = "EventGridKey")] IAsyncCollector<CloudEvent> eventCollector)
{
CloudEvent e = new CloudEvent("IncomingRequest", "IncomingRequest", await req.ReadAsStringAsync());
await eventCollector.AddAsync(e);
return new OkResult();
}
}
You can also output a string or JObject and the extension will attempt to parse into the correct strongly typed event.
Functions that uses Event Grid trigger
You can also create a function that will be executed whenever an event is delivered to your topic. Depending on the schema you have selected for your Azure Function event subscription, you can bind to either EventGridEvent
or CloudEvent
:
public static class EventGridEventTriggerFunction
{
[FunctionName("EventGridEventTriggerFunction")]
public static void Run(
ILogger logger,
[EventGridTrigger] EventGridEvent e)
{
logger.LogInformation("Event received {type} {subject}", e.EventType, e.Subject);
}
}
And if your subscription is configured with the CloudEvent schema:
public static class CloudEventTriggerFunction
{
[FunctionName("CloudEventTriggerFunction")]
public static void Run(
ILogger logger,
[EventGridTrigger] CloudEvent e)
{
logger.LogInformation("Event received {type} {subject}", e.Type, e.Subject);
}
}
Note that creating a subscription of type Azure Function with the CloudEvent schema is not yet supported. Instead, you can select an Endpoint Type of Web Hook and use your function URL as the endpoint. The function URL can be found by going to the Code + Test blade of your function, and clicking the Get function URL button.
Troubleshooting
Please refer to Monitor Azure Functions for troubleshooting guidance.
Next steps
Read the introduction to Azure Function or creating an Azure Function guide.
Contributing
See our CONTRIBUTING.md for details on building, testing, and contributing to this library.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.0 netstandard2.1 |
.NET Framework | net461 net462 net463 net47 net471 net472 net48 net481 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETStandard 2.0
- Azure.Messaging.EventGrid (>= 4.10.0)
- Microsoft.Azure.WebJobs (>= 3.0.33)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Microsoft.Azure.WebJobs.Extensions.EventGrid:
Package | Downloads |
---|---|
Microsoft.Azure.Workflows.WebJobs.Extension
Extensions for running workflows in Azure Functions |
|
WVHT.Microservices.JobManagementService.Worker
Job Management Worker functionality. |
GitHub repositories (5)
Showing the top 5 popular GitHub repositories that depend on Microsoft.Azure.WebJobs.Extensions.EventGrid:
Repository | Stars |
---|---|
Azure-Samples/Serverless-microservices-reference-architecture
This reference architecture walks you through the decision-making process involved in designing, developing, and delivering a serverless application using a microservices architecture through hands-on instructions for configuring and deploying all of the architecture's components along the way. The goal is to provide practical hands-on experience in working with several Azure services and the technologies that effectively use them in a cohesive and unified way to build a serverless-based microservices architecture.
|
|
MicrosoftLearning/AZ-220-Microsoft-Azure-IoT-Developer
AZ-220: Microsoft Azure IoT Developer
|
|
microsoft/MCW-Serverless-architecture
MCW Serverless architecture
|
|
microsoft/IgniteTheTour
Microsoft Ignite The Tour
|
|
microsoft/ignite-learning-paths-training-mod
Microsoft Ignite Learning Path, Train the Trainer materials: Modernizing Web Applications and Data
|
Version | Downloads | Last updated |
---|---|---|
3.2.1 | 330,200 | 9/8/2022 |
3.2.0 | 520,464 | 4/21/2022 |
3.1.0 | 289,599 | 1/13/2022 |
3.0.1 | 84,936 | 12/14/2021 |
3.0.0 | 108,729 | 10/26/2021 |
3.0.0-beta.4 | 14,036 | 10/11/2021 |
3.0.0-beta.3 | 161,579 | 6/9/2021 |
3.0.0-beta.2 | 18,379 | 5/13/2021 |
3.0.0-beta.1 | 20,916 | 3/23/2021 |
2.1.0 | 2,681,871 | 10/19/2019 |
2.0.0 | 739,499 | 9/19/2018 |
2.0.0-rc1 | 1,433 | 9/14/2018 |
2.0.0-beta4 | 5,800 | 8/30/2018 |
2.0.0-beta3 | 866 | 8/30/2018 |
2.0.0-beta2 | 2,164 | 7/6/2018 |
2.0.0-beta1 | 6,323 | 3/30/2018 |
1.0.0 | 176,863 | 7/6/2018 |
1.0.0-beta4 | 49,097 | 4/4/2018 |
1.0.0-beta3 | 4,924 | 3/1/2018 |
1.0.0-beta2 | 4,552 | 9/25/2017 |
1.0.0-beta1-10006 | 870 | 8/16/2017 |
1.0.0-beta1 | 1,085 | 9/25/2017 |