-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fdfa61c
Add EventGrid samples and readme
pakrym 43c1b91
Remove condition
pakrym bc1db8b
Nicer names
pakrym eb04224
remove en-us
pakrym ab25fc4
Update sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/REA…
pakrym 9092138
Update sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/REA…
pakrym File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
93 changes: 86 additions & 7 deletions
93
sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 output binding | ||
|
|
||
| Please follow the [binding tutorial](https://docs.microsoft.com/azure/azure-functions/functions-bindings-event-grid-trigger?tabs) to learn about using this extension for publishing EventGrid events. | ||
|
|
||
| ### 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...id/Microsoft.Azure.WebJobs.Extensions.EventGrid/tests/Samples/EventGridBindingFunction.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
23 changes: 23 additions & 0 deletions
23
...id/Microsoft.Azure.WebJobs.Extensions.EventGrid/tests/Samples/EventGridTriggerFunction.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.