CloudNative CloudEvent support for Azure.Messaging.EventGrid library for .NET
This library can be used to enable publishing CloudNative CloudEvents using the Azure Event Grid library.
Getting started
Install the package
Install the client library from NuGet:
dotnet add package Microsoft.Azure.Messaging.EventGrid.CloudNativeCloudEvents --prerelease
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 client library to interact with a topic or domain, 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"
Creating and Authenticating EventGridPublisherClient
Once you have your access key and topic endpoint, you can create the publisher client as follows:
EventGridPublisherClient client = new EventGridPublisherClient(
new Uri("<endpoint>"),
new AzureKeyCredential("<access-key>"));
Key concepts
For information about general Event Grid concepts: Concepts in Azure Event Grid.
For detailed information about the Event Grid client library concepts: Event Grid Client Library
Examples
EventGridPublisherClient client = new EventGridPublisherClient(
new Uri(TestEnvironment.CloudEventTopicHost),
new AzureKeyCredential(TestEnvironment.CloudEventTopicKey));
var cloudEvent =
new CloudEvent
{
Type = "record",
Source = new Uri("http://www.contoso.com"),
Data = "data"
};
await client.SendCloudNativeCloudEventAsync(cloudEvent);
Troubleshooting
For troubleshooting information, see the Event Grid Client Library documentation.
Next steps
View more samples here for common usages of the library.
Contributing
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 https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
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.
Azure SDK for .NET