Skip to content

Commit dc7ec06

Browse files
authored
Merge pull request #218855 from spelluru/customqueue1117
Custom event - Queue storage - review & update
2 parents 02f71fd + 5d74d45 commit dc7ec06

File tree

2 files changed

+43
-31
lines changed

2 files changed

+43
-31
lines changed

articles/event-grid/custom-event-to-queue-storage.md

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
---
22
title: 'Quickstart: Send custom events to storage queue - Event Grid, Azure CLI'
33
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
55
ms.topic: quickstart
66
ms.custom: devx-track-azurecli, mode-api
77
---
88

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
1010

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:
1212

13-
[!INCLUDE [quickstarts-free-trial-note.md](../../includes/quickstarts-free-trial-note.md)]
14-
15-
[!INCLUDE [azure-cli-prepare-your-environment.md](../../includes/azure-cli-prepare-your-environment.md)]
16-
17-
- 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/).
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.
2017

21-
This article gives you commands for using Azure CLI.
18+
[!INCLUDE [quickstarts-free-trial-note.md](../../includes/quickstarts-free-trial-note.md)]
2219

2320
## Create a resource group
2421

2522
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.
2623

27-
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.
2825

29-
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.
3028
3129
```azurecli-interactive
3230
az group create --name gridResourceGroup --location westus2
@@ -38,38 +36,52 @@ az group create --name gridResourceGroup --location westus2
3836

3937
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.
4038

41-
```azurecli-interactive
42-
az eventgrid topic create --name <topic_name> -l westus2 -g gridResourceGroup
43-
```
39+
1. Specify a name for the topic.
40+
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+
```
4449
4550
## Create Queue storage
4651
4752
Before subscribing to the custom topic, let's create the endpoint for the event message. You create a Queue storage for collecting the events.
4853
49-
```azurecli-interactive
50-
storagename="<unique-storage-name>"
51-
queuename="eventqueue"
54+
1. Specify a unique name for the Azure Storage account.
5255
53-
az storage account create -n $storagename -g gridResourceGroup -l westus2 --sku Standard_LRS
54-
az storage queue create --name $queuename --account-name $storagename
55-
```
56+
```azurecli-interactive
57+
storagename="<STORAGE ACCOUNT NAME>"
58+
```
59+
1. Run the following commands to create an Azure Storage account and a queue (named `eventqueue`) in the storage.
60+
61+
```azurecli-interactive
62+
queuename="eventqueue"
63+
64+
az storage account create -n $storagename -g gridResourceGroup -l westus2 --sku Standard_LRS
65+
key="$(az storage account keys list -n $storagename --query "[0].{value:value}" --output tsv)"
66+
az storage queue create --name $queuename --account-name $storagename --account-key $key
67+
```
5668
5769
## Subscribe to a custom topic
5870
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:
71+
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:
6072
61-
`/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/Microsoft.Storage/storageAccounts/<storage-name>/queueservices/default/queues/<queue-name>`
73+
`/subscriptions/<AZURE SUBSCRIPTION ID>/resourcegroups/<RESOURCE GROUP NAME>/providers/Microsoft.Storage/storageAccounts/<STORAGE ACCOUNT NAME>/queueservices/default/queues/<QUEUE NAME>`
6274
6375
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.
6476
6577
```azurecli-interactive
6678
storageid=$(az storage account show --name $storagename --resource-group gridResourceGroup --query id --output tsv)
6779
queueid="$storageid/queueservices/default/queues/$queuename"
68-
topicid=$(az eventgrid topic show --name <topic_name> -g gridResourceGroup --query id --output tsv)
80+
topicid=$(az eventgrid topic show --name $topicname -g gridResourceGroup --query id --output tsv)
6981
7082
az eventgrid event-subscription create \
7183
--source-resource-id $topicid \
72-
--name <event_subscription_name> \
84+
--name mystoragequeuesubscription \
7385
--endpoint-type storagequeue \
7486
--endpoint $queueid \
7587
--expiration-date "<yyyy-mm-dd>"
@@ -91,14 +103,14 @@ If you use the REST API to create the subscription, you pass the ID of the stora
91103

92104
## Send an event to your custom topic
93105

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>`.
106+
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.
95107

96108
```azurecli-interactive
97-
endpoint=$(az eventgrid topic show --name <topic_name> -g gridResourceGroup --query "endpoint" --output tsv)
98-
key=$(az eventgrid topic key list --name <topic_name> -g gridResourceGroup --query "key1" --output tsv)
109+
endpoint=$(az eventgrid topic show --name $topicname -g gridResourceGroup --query "endpoint" --output tsv)
110+
key=$(az eventgrid topic key list --name $topicname -g gridResourceGroup --query "key1" --output tsv)
99111
```
100112

101-
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:
113+
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:
102114

103115
```azurecli-interactive
104116
for i in 1 2 3
@@ -110,7 +122,7 @@ done
110122

111123
Navigate to the Queue storage in the portal, and notice that Event Grid sent those three events to the queue.
112124

113-
![Show messages](./media/custom-event-to-queue-storage/messages.png)
125+
:::image type="content" source="./media/custom-event-to-queue-storage/messages.png" alt-text="Screenshot showing the list of messages in the queue that are received from Event Grid.":::
114126

115127
> [!NOTE]
116128
> If you use an [Azure Queue storage trigger for Azure Functions](../azure-functions/functions-bindings-storage-queue-trigger.md) for a queue that receives messages from Event Grid, you may see the following error message on the function execution: `The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.`
14.5 KB
Loading

0 commit comments

Comments
 (0)