Azure Event Grid was introduced in August 2017 as the eventing backplane for Azure and beyond. It underpins many of our goals, and much of our vision for Serverless cloud computing. One of the core concepts of Azure Event Grid is making the cloud broadly reactive and introducing concepts that are familiar with reactive frameworks and models. In doing this, we have made Azure Event Grid a push based system that notifies you when events occur. While this push concept is central to the reactive architecture, there are times when receiving a webhook may present challenges, particularly at scale. For this reason we have introduced Event Hubs as a new subscription endpoint type available for Azure Event Grid.
Today, this feature is available via the CLI by using the --endpoint-type parameter and specifying eventhub instead of the default webhook. When using this option, you specify the endpoint as the Azure Resource Manager path of the Event Hub you want to send the events to. Assuming you already have an Event Hub, you can get this resource path and navigate to your Event Hub in the portal. You can also copy the path out of the URL, or you can list the resource using the CLI commands shown below.
Set the variables below to make your life easier.
eventHub=<your Event Hub name> eventHubNamespace=<your Event Hubs namespace here> resourceGroup=<your resource group name>
eventHubResource=$(az resource list --resource-group $resourceGroup --resource-type Microsoft.EventHub/namespaces | jq -r ". | select(.name==\"$eventHubNamespace\") | .id")
Now create the event subscription with the endpoint being your Event Hub.
az eventgrid resource event-subscription create --endpoint $eventHubResource/eventHubs/$eventHub --name myehsub --resource-group $resourceGroup--resource-type storageAccounts --provider-namespace Microsoft.Storage --resource-name mystorageaccount --endpoint-type eventhub
The output will show the JSON for the event subscription resource.
At this point you're ready to rock 'n roll. Anytime you create or delete blobs in this storage account an event will be delivered to your Event Hub. To learn more and see this data, check out the articles Get started receiving messages with the Event Processor Host in .NET Standard and Receive events from Azure Event Hubs using Java.
Also, you can still use the other CLI parameters to create prefix and suffix filters for this event subscription. If you wanted to only receive events for creating blobs you would add the parameter below:
If you also wanted to only receive notifications for .xml files you could add the parameter below:
You may have noticed that you didn't need to provide the connection string to the Event Hub. Since this is all in the Azure ecosystem and you're logged into Azure CLI, the resource manager will RBAC your ability to get the Event Hub connection string after which we use to do service to service authentication, so there is no need to provide a connection string.