Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The article provides step-by-step instructions to publish events to Azure Event Grid in the CloudEvents JSON format and deliver those events by using the push delivery model.
To be specific, you use Azure portal and Curl to publish events to a namespace topic in Event Grid and push those events from an event subscription to an Event Hubs handler destination. For more information about the push delivery model, see Push delivery overview.
If you don't have an Azure subscription, create an Azure free account before you begin.
An Event Grid namespace provides a user-defined endpoint to which you post your events. The following example creates a namespace in your resource group using Bash in Azure Cloud Shell. The namespace name must be unique because it's part of a Domain Name System (DNS) entry.
Navigate to the Azure portal.
In the search bar at the topic, type Event Grid Namespaces
, and select Event Grid Namespaces
from the results.
On the Event Grid Namespaces page, select + Create on the command bar.
On the Create Namespace page, follow these steps:
On the Deployment page, select Go to resource after the successful deployment.
Enable system assigned managed identity in the Event Grid namespace. To deliver events to event hubs in your Event Hubs namespace using managed identity, follow these steps:
In this section, you enable a system-assigned managed identity on the namespace. You do the other steps later in this quickstart.
On the Event Grid Namespace page, select Identity on the left menu.
On the Identity page, select On for the Status.
Select Save on the command bar.
Create a topic that's used to hold all events published to the namespace endpoint.
Create an Event Hubs resource that is used as the handler destination for the namespace topic push delivery subscription. Do these steps in a separate tab of your internet browser or in a separate window. Navigate to the Azure portal and sign in using the same credentials you used before and the same Azure subscription.
Create an event subscription setting its delivery mode to Push, which supports push delivery.
Now, send a sample event to the namespace topic by following steps in this section.
Launch Cloud Shell in the Azure portal. Switch to Bash.
In the Cloud Shell, run the following command to declare a variable to hold the access key for the namespace. You noted the access key earlier in this quickstart.
key=ACCESSKEY
Declare a variable to hold the publishing operation URI. Replace NAMESPACENAME
with the name of your Event Grid namespace and TOPICNAME
with the name of the topic.
publish_operation_uri=https://NAMESPACENAME.eastus-1.eventgrid.azure.net/topics/TOPICNAME:publish?api-version=2023-06-01-preview
Create a sample CloudEvents compliant event:
event=' { "specversion": "1.0", "id": "'"$RANDOM"'", "type": "com.yourcompany.order.ordercreatedV2", "source" : "/mycontext", "subject": "orders/O-234595", "time": "'`date +%Y-%m-%dT%H:%M:%SZ`'", "datacontenttype" : "application/json", "data":{ "orderId": "O-234595", "url": "https://yourcompany.com/orders/o-234595"}} '
The data
element is the payload of your event. Any well-formed JSON can go in this field. For more information on properties (also known as context attributes) that can go in an event, see the CloudEvents specifications.
Use CURL to send the event to the topic. CURL is a utility that sends HTTP requests.
curl -X POST -H "Content-Type: application/cloudevents+json" -H "Authorization:SharedAccessKey $key" -d "$event" $publish_operation_uri
Navigate to the Event Hubs Namespace page in the Azure portal, refresh the page and verify that incoming messages counter in the chart indicates that an event has been received.
In this article, you created and configured the Event Grid namespace and Event Hubs resources. For step-by-step instructions to receive events from an event hub, see these tutorials:
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Enable reliable messaging for Big Data applications using Azure Event Hubs - Training
Learn to use Azure Event Hubs to reliably process high-volume data streams to enable you to code applications to send and receive messages through the hub.
Certification
Microsoft Certified: Azure Administrator Associate - Certifications
Demonstrate key skills to configure, manage, secure, and administer key professional functions in Microsoft Azure.
Documentation
Deliver events to Azure Event Hubs using push model (CLI) - Azure Event Grid
This article provides step-by-step instructions to publish to Azure Event Grid in the CloudEvents JSON format and deliver those events by using the push delivery model.
Quickstart: Send custom events to an event hub - Event Grid, Azure CLI - Azure Event Grid
Learn how to use Azure Event Grid and the Azure CLI to publish a topic and subscribe to that event, by using an event hub for the endpoint.
Event hub as an event handler for Azure Event Grid events - Azure Event Grid
Describes how you can use event hubs as event handlers for Azure Event Grid events.