-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add EventGrid samples and readme #15461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
fdfa61c
43c1b91
bc1db8b
eb04224
ab25fc4
9092138
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| # Release History | ||
|
|
||
| ## 3.0.0-beta.1 (Unreleased) | ||
|
|
||
| - The initial release of Microsoft.Azure.WebJobs.Extensions.EventGrid 3.0.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,113 @@ | ||
| # Azure WebJobs EventGrid client library for .NET | ||
|
|
||
| TODO | ||
| 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][nuget]: | ||
|
|
||
| ```Powershell | ||
| dotnet add package Microsoft.Azure.WebJobs.Extensions.EventGrid | ||
| ``` | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| You must have an [Azure subscription](https://azure.microsoft.com/free/) and an Azure resource group with a custom Event Grid topic or domain. Follow this [step-by-step tutorial](https://docs.microsoft.com/azure/event-grid/custom-event-quickstart-portal) to register the Event Grid resource provider and create Event Grid topics using the [Azure portal](https://portal.azure.com/). There is a [similar tutorial](https://docs.microsoft.com/azure/event-grid/custom-event-quickstart) using [Azure CLI](https://docs.microsoft.com/cli/azure). | ||
|
|
||
| ### 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. | ||
|
|
||
| ### Authenticate the client | ||
| You can find the endpoint for your Event Grid topic either in the [Azure Portal](https://portal.azure.com/) or by using the [Azure CLI](https://docs.microsoft.com/cli/azure) snippet below. | ||
|
|
||
| ```bash | ||
| 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](https://docs.microsoft.com/azure/event-grid/get-access-keys), or by using the Azure CLI snippet below: | ||
| ```bash | ||
| az eventgrid topic key list --name <your-resource-name> --resource-group <your-resource-group-name> --query "key1" | ||
| ``` | ||
|
|
||
| ## Key concepts | ||
|
|
||
| TODO | ||
| ### Using Event Grid binding | ||
pakrym marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Please follow the [binding tutorial](https://docs.microsoft.com/azure/azure-functions/functions-bindings-event-grid-trigger?tabs) to lean about using this extension for publishing EventGrid events. | ||
pakrym marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
pakrym marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Using Event Grid trigger | ||
|
|
||
| Please follow the [tutorial](https://docs.microsoft.com/azure/azure-functions/functions-bindings-event-grid-trigger?tabs=csharp) to learn about triggering an Azure Function when an event is published. | ||
|
|
||
| ## Examples | ||
|
|
||
| TODO | ||
| ### Functions that uses Event Grid binding | ||
|
|
||
| ```C# Snippet:EventGridBindingFunction | ||
| public static class EventGridBindingFunction | ||
| { | ||
| [FunctionName("EventGridBindingFunction")] | ||
| 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(); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Functions that uses Event Grid trigger | ||
|
|
||
| ```C# Snippet:EventGridTriggerFunction | ||
| public static class EventGridTriggerFunction | ||
| { | ||
| [FunctionName("EventGridTriggerFunction")] | ||
| public static void Run( | ||
| ILogger logger, | ||
| [EventGridTrigger] EventGridEvent e) | ||
| { | ||
| logger.LogInformation("Event received {type} {subject}", e.EventType, e.Subject); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| TODO | ||
| Please refer to [Monitor Azure Functions](https://docs.microsoft.com/azure/azure-functions/functions-monitoring) for troubleshooting guidance. | ||
|
|
||
| ## Next steps | ||
|
|
||
| TODO | ||
| Read the [introduction to Azure Function](https://docs.microsoft.com/azure/azure-functions/functions-overview) or [creating an Azure Function guide](https://docs.microsoft.com/azure/azure-functions/functions-create-first-azure-function). | ||
|
|
||
| ## Contributing | ||
|
|
||
| TODO | ||
| See our [CONTRIBUTING.md][contrib] 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][cla]. | ||
|
|
||
| This project has adopted the [Microsoft Open Source Code of Conduct][coc]. | ||
| For more information see the [Code of Conduct FAQ][coc_faq] | ||
| or contact [[email protected]][coc_contact] with any | ||
| additional questions or comments. | ||
|
|
||
|  | ||
|
|
||
| <!-- LINKS --> | ||
| [source]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/search/Microsoft.Azure.WebJobs.Extensions.EventGrid/src | ||
| [package]: https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.EventGrid/ | ||
| [docs]: https://docs.microsoft.com/dotnet/api/Microsoft.Azure.WebJobs.Extensions.EventGrid | ||
| [nuget]: https://www.nuget.org/ | ||
|
|
||
| [contrib]: https://github.com/Azure/azure-sdk-for-net/tree/master/CONTRIBUTING.md | ||
| [cla]: https://cla.microsoft.com | ||
| [coc]: https://opensource.microsoft.com/codeofconduct/ | ||
| [coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ | ||
| [coc_contact]: mailto:[email protected] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using System.Web; | ||
| using Azure; | ||
| using Azure.Messaging.EventGrid; | ||
| using Microsoft.Azure.WebJobs.Description; | ||
| using Microsoft.Azure.WebJobs.Host.Bindings; | ||
|
|
@@ -42,7 +43,7 @@ internal EventGridExtensionConfigProvider(Func<EventGridAttribute, IAsyncCollect | |
| // default constructor | ||
| public EventGridExtensionConfigProvider(ILoggerFactory loggerFactory) | ||
| { | ||
| _converter = (attr => new EventGridAsyncCollector(new EventGridPublisherClient(new Uri(attr.TopicEndpointUri), new EventGridSharedAccessSignatureCredential(attr.TopicKeySetting)))); | ||
| _converter = (attr => new EventGridAsyncCollector(new EventGridPublisherClient(new Uri(attr.TopicEndpointUri), new AzureKeyCredential(attr.TopicKeySetting)))); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR: Is there something we could have done in the EventGrid SDK Documentation itself to make it clear which of these you needed to use?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a comment from ApiView about a potential rename of the type to include SAS in the name. Not sure if that would have helped. |
||
| _loggerFactory = loggerFactory; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Threading.Tasks; | ||
| using Azure.Messaging.EventGrid; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.Azure.WebJobs; | ||
| using Microsoft.Azure.WebJobs.Extensions.Http; | ||
| using Microsoft.Azure.WebJobs.Extensions.EventGrid; | ||
|
|
||
| namespace Azure.Extensions.WebJobs.Sample | ||
| { | ||
| #region Snippet:EventGridBindingFunction | ||
| public static class EventGridBindingFunction | ||
| { | ||
| [FunctionName("EventGridBindingFunction")] | ||
| 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(); | ||
| } | ||
| } | ||
| #endregion | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Azure.WebJobs; | ||
| using Microsoft.Azure.WebJobs.Extensions.EventGrid; | ||
| using Azure.Messaging.EventGrid; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Azure.Extensions.WebJobs.Sample | ||
| { | ||
| #region Snippet:EventGridTriggerFunction | ||
| public static class EventGridTriggerFunction | ||
| { | ||
| [FunctionName("EventGridTriggerFunction")] | ||
| public static void Run( | ||
| ILogger logger, | ||
| [EventGridTrigger] EventGridEvent e) | ||
| { | ||
| logger.LogInformation("Event received {type} {subject}", e.EventType, e.Subject); | ||
| } | ||
| } | ||
| #endregion | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.