You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: 'Quickstart: Use Azure Event Grid and Azure CLI to publish a topic, and subscribe to that event. An event hub is used for the endpoint.'
2
+
title: 'Quickstart: Send custom events to an event hub - Event Grid, Azure CLI'
3
+
description: 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.
4
4
ms.date: 01/31/2024
5
5
ms.topic: quickstart
6
6
ms.custom: devx-track-azurecli, mode-api
7
7
---
8
8
9
-
# Quickstart: Route custom events to Azure Event Hubs with Azure CLI and Event Grid
9
+
# Quickstart: Route custom events to an event hub by using Event Grid and the Azure CLI
10
10
11
-
[Azure Event Grid](overview.md) is a highly scalable and serverless event broker that you can use to integrate applications using events. Event Grid delivers events to [supported event handlers](event-handlers.md) and Azure Event Hubs is one of them. In this article, you use Azure CLI for the following steps:
11
+
[Azure Event Grid](overview.md) is a highly scalable and serverless event broker that you can use to integrate applications via events. Event Grid delivers events to [supported event handlers](event-handlers.md), and Azure Event Hubs is one of them.
12
12
13
-
1. Create an Event Grid custom topic.
14
-
1. Create an Azure Event Hubs subscription for the custom topic.
15
-
1. Send sample events to the custom topic.
16
-
1. Verify that those events are delivered to the event hub.
13
+
In this quickstart, you use the Azure CLI to create an Event Grid custom topic and an Event Hubs subscription for that topic. You then send sample events to the custom topic and verify that those events are delivered to an event hub.
Event Grid topics are Azure resources, and must be placed in an Azure resource group. The resource group is a logical collection into which Azure resources are deployed and managed.
19
+
Event Grid topics are Azure resources, and they must be placed in an Azure resource group. The resource group is a logical collection into which Azure resources are deployed and managed.
23
20
24
-
Create a resource group with the [az group create](/cli/azure/group#az-group-create) command. The following example creates a resource group named **gridResourceGroup** in the **westus2** location.
21
+
Create a resource group by using the [az group create](/cli/azure/group#az-group-create) command. The following example creates a resource group named `gridResourceGroup` in the `westus2` location.
25
22
26
-
> [!NOTE]
27
-
> Select **Try it** next to the CLI example to launch Cloud Shell in the right pane. Select **Copy** button to copy the command, paste it in the Cloud Shell window, and then press ENTER to run the command.
23
+
Select **Open Cloud Shell** to open Azure Cloud Shell on the right pane. Select the **Copy** button to copy the command, paste it in Cloud Shell, and then select the Enter key to run the command.
28
24
29
25
```azurecli-interactive
30
26
az group create --name gridResourceGroup --location westus2
@@ -34,30 +30,33 @@ az group create --name gridResourceGroup --location westus2
34
30
35
31
## Create a custom topic
36
32
37
-
An Event Grid topic provides a user-defined endpoint that you post your events to. The following example creates the custom topic in your resource group. Replace `<topic_name>` with a unique name for your custom topic. The Event Grid topic name must be unique because it's represented by a Domain Name System (DNS) entry.
33
+
An Event Grid topic provides a user-defined endpoint that you post your events to. The following example creates the custom topic in your resource group.
38
34
39
-
1. Specify a name for the topic.
35
+
Replace `<TOPIC NAME>` with a unique name for your custom topic. The Event Grid topic name must be unique because a Domain Name System (DNS) entry represents it.
36
+
37
+
1. Specify a name for the topic:
40
38
41
39
```azurecli-interactive
42
40
topicname="<TOPIC NAME>"
43
-
```
44
-
1. Run the following command to create the topic.
41
+
```
42
+
43
+
1. Run the following command to create the topic:
45
44
46
45
```azurecli-interactive
47
46
az eventgrid topic create --name $topicname -l westus2 -g gridResourceGroup
48
47
```
49
48
50
49
## Create an event hub
51
50
52
-
Before subscribing to the custom topic, let's create the endpoint for the event message. You create an event hub for collecting the events.
51
+
Before you subscribe to the custom topic, create the endpoint for the event message. You create an event hub for collecting the events.
53
52
54
-
1. Specify a unique name for the Event Hubs namespace.
53
+
1. Specify a unique name for the Event Hubs namespace:
55
54
56
55
```azurecli-interactive
57
56
namespace="<EVENT HUBS NAMESPACE NAME>"
58
57
```
59
-
1. Run the following commands to create an Event Hubs namespace and an event hub named `demohub` in that namespace.
60
58
59
+
1. Run the following commands to create an Event Hubs namespace and an event hub named `demohub` in that namespace:
61
60
62
61
```azurecli-interactive
63
62
hubname=demohub
@@ -68,11 +67,11 @@ Before subscribing to the custom topic, let's create the endpoint for the event
68
67
69
68
## Subscribe to a custom topic
70
69
71
-
You subscribe to an Event Grid topic to tell Event Grid which events you want to track. The following example subscribes to the custom topic you created, and passes the resource ID of the event hub for the endpoint. The endpoint is in the format:
70
+
You subscribe to an Event Grid topic to tell Event Grid which events you want to track. The following example subscribes to the custom topic that you created, and it passes the resource ID of the event hub for the endpoint. The endpoint is in this format:
72
71
73
72
`/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventHub/namespaces/<NAMESPACE NAME>/eventhubs/<EVENT HUB NAME>`
74
73
75
-
The following script gets the resource ID for the event hub, and subscribes to an Event Grid topic. It sets the endpoint type to `eventhub` and uses the event hub ID for the endpoint.
74
+
The following script gets the resource ID for the event hub and subscribes to an Event Grid topic. It sets the endpoint type to `eventhub` and uses the event hub ID for the endpoint.
76
75
77
76
```azurecli-interactive
78
77
hubid=$(az eventhubs eventhub show --name $hubname --namespace-name $namespace --resource-group gridResourceGroup --query id --output tsv)
@@ -89,14 +88,16 @@ The account that creates the event subscription must have write access to the ev
89
88
90
89
## Send an event to your custom topic
91
90
92
-
Let's trigger an event to see how Event Grid distributes the message to your endpoint. First, let's get the URL and key for the custom topic.
91
+
Trigger an event to see how Event Grid distributes the message to your endpoint. First, get the URL and key for the custom topic:
To simplify this article, you use sample event data to send to the custom topic. Typically, an application or Azure service would send the event data. CURL is a utility that sends HTTP requests. In this article, use CURL to send the event to the custom topic. The following example sends three events to the Event Grid topic:
98
+
For the sake of simplicity in this article, you use sample event data to send to the custom topic. Typically, an application or an Azure service would send the event data.
99
+
100
+
The cURL tool sends HTTP requests. In this article, you use cURL to send the event to the custom topic. The following example sends three events to the Event Grid topic:
100
101
101
102
```azurecli-interactive
102
103
for i in 1 2 3
@@ -106,33 +107,34 @@ do
106
107
done
107
108
```
108
109
109
-
On the **Overview** page for your Event Hubs namespace in the Azure portal, notice that Event Grid sent those three events to the event hub. You see the same chart on the **Overview** page for the `demohub` Event Hubs instance page.
110
+
In the Azure portal, on the **Overview** page for your Event Hubs namespace, notice that Event Grid sent those three events to the event hub. You see the same chart on the **Overview** page for the `demohub` Event Hubs instance.
110
111
111
-
:::image type="content" source="./media/custom-event-to-eventhub/show-result.png" lightbox="./media/custom-event-to-eventhub/show-result.png" alt-text="Image showing the portal page with incoming message count as 3.":::
112
+
:::image type="content" source="./media/custom-event-to-eventhub/show-result.png" lightbox="./media/custom-event-to-eventhub/show-result.png" alt-text="Screenshot that shows the portal page with an incoming message count of 3.":::
112
113
113
-
Typically, you create an application that retrieves the events from the event hub. To create an application that gets messages from an event hub, see:
114
+
Typically, you create an application that retrieves event messages from the event hub. For more information, see:
114
115
115
-
*[Get started receiving messages with the Event Processor Host in .NET Standard](../event-hubs/event-hubs-dotnet-standard-getstarted-send.md)
116
-
*[Receive events from Azure Event Hubs using Java](../event-hubs/event-hubs-java-get-started-send.md)
117
-
*[Receive events from Event Hubs using Apache Storm](../event-hubs/event-hubs-storm-getstarted-receive.md)
116
+
-[Get started receiving messages with the event processor host in .NET Standard](../event-hubs/event-hubs-dotnet-standard-getstarted-send.md)
117
+
-[Receive events from Azure Event Hubs by using Java](../event-hubs/event-hubs-java-get-started-send.md)
118
+
-[Receive events from Event Hubs by using Apache Storm](../event-hubs/event-hubs-storm-getstarted-receive.md)
118
119
119
120
## Clean up resources
120
-
If you plan to continue working with this event, don't clean up the resources created in this article. Otherwise, use the following command to delete the resources you created in this article.
121
+
122
+
If you plan to continue working with this event, don't clean up the resources that you created in this article. Otherwise, use the following command to delete the resources:
121
123
122
124
```azurecli-interactive
123
125
az group delete --name gridResourceGroup
124
126
```
125
127
126
-
## Next steps
128
+
## Related content
127
129
128
130
Now that you know how to create topics and event subscriptions, learn more about what Event Grid can help you do:
129
131
130
132
-[About Event Grid](overview.md)
131
-
-[Route Blob storage events to a custom web endpoint](../storage/blobs/storage-blob-event-quickstart.md?toc=%2fazure%2fevent-grid%2ftoc.json)
133
+
-[Route Azure Blob Storage events to a custom web endpoint](../storage/blobs/storage-blob-event-quickstart.md?toc=%2fazure%2fevent-grid%2ftoc.json)
132
134
-[Monitor virtual machine changes with Azure Event Grid and Logic Apps](monitor-virtual-machine-changes-logic-app.md)
133
135
-[Stream big data into a data warehouse](event-hubs-integration.md)
134
136
135
-
See the following samples to learn about publishing events to and consuming events from Event Grid using different programming languages.
137
+
To learn about publishing events to, and consuming events from, Event Grid by using various programming languages, see the following samples:
136
138
137
139
-[Azure Event Grid samples for .NET](/samples/azure/azure-sdk-for-net/azure-event-grid-sdk-samples/)
138
140
-[Azure Event Grid samples for Java](/samples/azure/azure-sdk-for-java/eventgrid-samples/)
0 commit comments