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.'
4
-
ms.date: 09/28/2021
4
+
ms.date: 11/18/2022
5
5
ms.topic: quickstart
6
6
ms.custom: devx-track-azurecli, mode-api
7
7
---
8
8
9
9
# Quickstart: Route custom events to Azure Event Hubs with Azure CLI and Event Grid
10
10
11
-
Azure Event Grid is an eventing service for the cloud. Azure Event Hubs is one of the supported event handlers. In this article, you use the Azure CLI to create a custom topic, subscribe to the custom topic, and trigger the event to view the result. You send the events to an event hub.
11
+
[Azure Event Grid](overview.md) is a highly scalable and serverless event broker that you can use to integrate applications using events. Events are delivered by Event Grid 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:
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.
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.
18
23
19
-
Create a resource group with the [az group create](/cli/azure/group#az-group-create) command.
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.
20
25
21
-
The following example creates a resource group named *gridResourceGroup* in the *westus2* location.
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.
22
28
23
29
```azurecli-interactive
24
30
az group create --name gridResourceGroup --location westus2
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 `<your-topic-name>` with a unique name for your custom topic. The custom topic name must be unique because it's represented by a DNS entry.
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 DNS entry.
32
38
33
-
```azurecli-interactive
34
-
topicname=<your-topic-name>
35
-
```
39
+
1. Specify a name for the topic.
36
40
37
-
```azurecli-interactive
38
-
az eventgrid topic create --name $topicname -l westus2 -g gridResourceGroup
39
-
```
41
+
```azurecli-interactive
42
+
topicname="<TOPIC NAME>"
43
+
```
44
+
1. Run the following command to create the topic.
45
+
46
+
```azurecli-interactive
47
+
az eventgrid topic create --name $topicname -l westus2 -g gridResourceGroup
48
+
```
40
49
41
-
## Create event hub
50
+
## Create an event hub
42
51
43
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.
44
53
45
-
```azurecli-interactive
46
-
namespace=<unique-namespace-name>
47
-
```
54
+
1. Specify a unique name for the Event Hubs namespace.
48
55
49
-
```azurecli-interactive
50
-
hubname=demohub
56
+
```azurecli-interactive
57
+
namespace="<EVENT HUBS NAMESPACE NAME>"
58
+
```
59
+
1. Run the following commands to create an Event Hubs namespace and an event hub named `demohub` in that namespace.
51
60
52
-
az eventhubs namespace create --name $namespace --resource-group gridResourceGroup
53
-
az eventhubs eventhub create --name $hubname --namespace-name $namespace --resource-group gridResourceGroup
54
-
```
61
+
62
+
```azurecli-interactive
63
+
hubname=demohub
64
+
65
+
az eventhubs namespace create --name $namespace --resource-group gridResourceGroup
66
+
az eventhubs eventhub create --name $hubname --namespace-name $namespace --resource-group gridResourceGroup
67
+
```
55
68
56
69
## Subscribe to a custom topic
57
70
58
-
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:
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:
`/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventHub/namespaces/<NAMESPACE NAME>/eventhubs/<EVENT HUB NAME>`
61
74
62
-
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.
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.
63
76
64
77
```azurecli-interactive
65
78
hubid=$(az eventhubs eventhub show --name $hubname --namespace-name $namespace --resource-group gridResourceGroup --query id --output tsv)
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:
99
+
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:
87
100
88
101
```azurecli-interactive
89
102
for i in 1 2 3
@@ -93,7 +106,7 @@ do
93
106
done
94
107
```
95
108
96
-
Navigate to the event hub in the portal, and notice that Event Grid sent those three events to the event hub.
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'll see the same chart on the **Overview** page for the `demohub` Event Hubs instance page.
97
110
98
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.":::
Copy file name to clipboardExpand all lines: articles/event-grid/custom-event-to-queue-storage.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ az group create --name gridResourceGroup --location westus2
34
34
35
35
## Create a custom topic
36
36
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 DNS entry.
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 DNS entry.
38
38
39
39
1. Specify a name for the topic.
40
40
@@ -72,7 +72,11 @@ The following example subscribes to the custom topic you created, and passes the
72
72
73
73
`/subscriptions/<AZURE SUBSCRIPTION ID>/resourcegroups/<RESOURCE GROUP NAME>/providers/Microsoft.Storage/storageAccounts/<STORAGE ACCOUNT NAME>/queueservices/default/queues/<QUEUE NAME>`
74
74
75
-
The following script gets the resource ID of the storage account for the queue. It constructs the ID for the queue storage, and subscribes to an event grid topic. It sets the endpoint type to `storagequeue` and uses the queue ID for the endpoint.
75
+
The following script gets the resource ID of the storage account for the queue. It constructs the ID for the queue storage, and subscribes to an Event Grid topic. It sets the endpoint type to `storagequeue` and uses the queue ID for the endpoint.
76
+
77
+
78
+
> [!IMPORTANT]
79
+
> Replace expiration date placeholder (`<yyyy-mm-dd>`) with an actual value. For example: `2022-11-17` before running the command.
76
80
77
81
```azurecli-interactive
78
82
storageid=$(az storage account show --name $storagename --resource-group gridResourceGroup --query id --output tsv)
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, you use CURL to send the event to the custom topic. The following example sends three events to the event grid topic:
117
+
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, you use CURL to send the event to the custom topic. The following example sends three events to the Event Grid topic:
0 commit comments