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. A storage queue is used for the endpoint.'
4
-
ms.date: 02/02/2021
4
+
ms.date: 11/17/2022
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 Queue storage with Azure CLI and Event Grid
9
+
# Quickstart: Route custom events to Azure Queue storage via Event Grid using Azure CLI
10
10
11
-
Azure Event Grid is an eventing service for the cloud. Azure Queue storage 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 the Queue storage.
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 Queue storage 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 Queue subscription for the custom topic.
15
+
1. Send sample events to the custom topic.
16
+
1. Verify that those events are delivered to Azure Queue storage.
- This article requires version 2.0.56 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
18
-
19
-
- If you are using Azure PowerShell on your local machine instead of using Cloud Shell in the Azure portal, ensure that you have Azure PowerShell version 1.1.0 or greater. Download the latest version of Azure PowerShell on your Windows machine from [Azure downloads - Command-line tools](https://azure.microsoft.com/downloads/).
20
-
21
-
This article gives you commands for using Azure CLI.
22
-
23
22
## Create a resource group
24
23
25
24
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.
26
25
27
-
Create a resource group with the [az group create](/cli/azure/group#az-group-create) command.
28
-
29
-
The following example creates a resource group named *gridResourceGroup* in the *westus2* location.
26
+
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.
30
27
31
28
```azurecli-interactive
32
29
az group create --name gridResourceGroup --location westus2
@@ -38,27 +35,40 @@ az group create --name gridResourceGroup --location westus2
38
35
39
36
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.
40
37
38
+
1. Specify a name for the topic.
39
+
40
+
```azurecli-interactive
41
+
topicname="<TOPIC NAME>"
42
+
```
43
+
1. Run the following command to create the topic.
44
+
41
45
```azurecli-interactive
42
-
az eventgrid topic create --name <topic_name> -l westus2 -g gridResourceGroup
46
+
az eventgrid topic create --name $topicname -l westus2 -g gridResourceGroup
43
47
```
44
48
45
49
## Create Queue storage
46
50
47
51
Before subscribing to the custom topic, let's create the endpoint for the event message. You create a Queue storage for collecting the events.
48
52
49
-
```azurecli-interactive
50
-
storagename="<unique-storage-name>"
51
-
queuename="eventqueue"
53
+
1. Specify a unique name for the Azure Storage account.
az storage queue create --name $queuename --account-name $storagename
65
+
```
56
66
57
67
## Subscribe to a custom topic
58
68
59
-
You subscribe to a custom 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 Queue storage for the endpoint. With Azure CLI, you pass the Queue storage ID as the endpoint. The endpoint is in the format:
69
+
The following example subscribes to the custom topic you created, and passes the resource ID of the Queue storage for the endpoint. With Azure CLI, you pass the Queue storage ID as the endpoint. The endpoint is in the format:
`/subscriptions/<AZURE SUBSCRIPTION ID>/resourcegroups/<RESOURCE GROUP NAME>/providers/Microsoft.Storage/storageAccounts/<STORAGE ACCOUNT NAME>/queueservices/default/queues/<QUEUE NAME>`
62
72
63
73
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.
64
74
@@ -91,14 +101,14 @@ If you use the REST API to create the subscription, you pass the ID of the stora
91
101
92
102
## Send an event to your custom topic
93
103
94
-
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. Again, use your custom topic name for `<topic_name>`.
104
+
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.
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:
111
+
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