Skip to content

Commit 27f7575

Browse files
authored
Merge pull request #301643 from TimShererWithAquent/us439357-01
Freshness Edit: Azure Event Grid (1 of 7)
2 parents d0e8722 + 605f708 commit 27f7575

File tree

2 files changed

+118
-96
lines changed

2 files changed

+118
-96
lines changed

articles/event-grid/includes/register-provider-cli.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
author: spelluru
55
ms.service: azure-event-grid
66
ms.topic: include
7-
ms.date: 08/17/2018
7+
ms.date: 06/23/2025
88
ms.author: spelluru
99
ms.custom: include file
1010
---
1111

1212
## Enable the Event Grid resource provider
1313

14-
1. If you haven't previously used Event Grid in your Azure subscription, you might need to register the Event Grid resource provider. Run the following command to register the provider:
14+
1. If this is the first time you're using Event Grid in your Azure subscription, you might need to register the Event Grid resource provider. Run the following command to register the provider:
1515

1616
```azurecli-interactive
1717
az provider register --namespace Microsoft.EventGrid
1818
```
1919
20-
2. It might take a moment for the registration to finish. To check the status, run the following command:
20+
1. It might take a moment for the registration to finish. To check the status, run the following command:
2121
2222
```azurecli-interactive
2323
az provider show --namespace Microsoft.EventGrid --query "registrationState"
Lines changed: 115 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,49 @@
11
---
2-
title: Publish and consume events using namespace topics
3-
description: This article provides step-by-step instructions to publish events to Azure Event Grid in the CloudEvents JSON format and consume those events by using the pull delivery model.
2+
title: "Quickstart: Publish and Consume Events Using Namespace Topics"
3+
description: Learn how to publish events to Azure Event Grid in the CloudEvents JSON format and consume those events by using the pull delivery model.
44
ms.topic: quickstart
55
ms.custom: ignite-2023, devx-track-azurecli, build-2024
66
ms.author: robece
77
author: robece
8-
ms.date: 02/20/2024
8+
ms.date: 06/23/2025
9+
#customer intent: As a developer, I want to use the pull delivery model to publish and consume events using Azure Event Grid.
910
---
1011

11-
# Publish to namespace topics and consume events in Azure Event Grid
12+
# Quickstart: Publish to namespace topics and consume events in Azure Event Grid
1213

13-
This article provides a quick introduction to pull delivery using the ``curl`` bash shell command to publish, receive, and acknowledge events. Event Grid resources are created using CLI commands. This article is suitable for a quick test of the pull delivery functionality. For sample code using the data plane SDKs, see the [.NET](event-grid-dotnet-get-started-pull-delivery.md) or the Java samples. For Java, we provide the sample code in two articles: [publish events](publish-events-to-namespace-topics-java.md) and [receive events](receive-events-from-namespace-topics-java.md) quickstarts.
14-
For more information about the pull delivery model, see the [concepts](concepts-event-grid-namespaces.md) and [pull delivery overview](pull-delivery-overview.md) articles.
14+
In this quickstart, you do pull delivery using the `curl` bash shell command to publish, receive, and acknowledge events. Use Azure CLI commands to create Azure Event Grid resources. This article is suitable for a quick test of the pull delivery functionality.
15+
16+
For sample code that uses the data plane SDKs, see these resources:
17+
18+
- .NET: [Send and receive messages from an Azure Event Grid namespace topic (.NET)](event-grid-dotnet-get-started-pull-delivery.md)
19+
- Java: [Publish events to namespace topics using Java](publish-events-to-namespace-topics-java.md)
20+
- Java: [Receive events using pull delivery with Java](receive-events-from-namespace-topics-java.md)
21+
22+
For more information about the pull delivery model, see [Azure Event Grid namespace concepts](concepts-event-grid-namespaces.md) and [Pull delivery with HTTP](pull-delivery-overview.md) articles.
1523

1624
[!INCLUDE [quickstarts-free-trial-note.md](~/reusable-content/ce-skilling/azure/includes/quickstarts-free-trial-note.md)]
1725

1826
[!INCLUDE [azure-cli-prepare-your-environment.md](~/reusable-content/azure-cli/azure-cli-prepare-your-environment.md)]
1927

20-
- This article requires version 2.0.70 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
28+
- This article requires version 2.0.70 or later of the Azure CLI. If you use Azure Cloud Shell, the latest version is already installed.
2129

2230
## Create a resource group
23-
Create an Azure resource group with the [az group create](/cli/azure/group#az-group-create) command. You use this resource group to contain all resources created in this article.
31+
32+
Create an Azure resource group with the [az group create](/cli/azure/group#az-group-create) command. Use this resource group to contain all resources you create in this article.
2433

2534
The general steps to use Cloud Shell to run commands are:
2635

2736
- Select **Open Cloud Shell** to see an Azure Cloud Shell window on the right pane.
2837
- Copy the command and paste into the Azure Cloud Shell window.
2938
- Press ENTER to run the command.
3039

31-
1. Declare a variable to hold the name of an Azure resource group. Specify a name for the resource group by replacing `<your-resource-group-name>` with a value you like.
40+
1. Declare a variable to hold the name of an Azure resource group. Specify a name for the resource group by replacing `<your-resource-group-name>` with your value.
3241

3342
```azurecli-interactive
3443
resource_group="<your-resource-group-name>"
3544
```
36-
2. Create a resource group. Change the location as you see fit.
45+
46+
1. Create a resource group. You can change the location to any Azure location.
3747
3848
```azurecli-interactive
3949
az group create --name $resource_group --location eastus
@@ -47,131 +57,143 @@ An Event Grid namespace provides a user-defined endpoint to which you post your
4757
4858
- It should be between 3-50 characters.
4959
- It should be regionally unique.
50-
- Only allowed characters are a-z, A-Z, 0-9 and -
51-
- It shouldn't start with reserved key word prefixes like `Microsoft`, `System` or `EventGrid`.
60+
- Only allowed characters are: a-z, A-Z, 0-9, and -
61+
- It shouldn't start with reserved key word prefixes like `Microsoft`, `System`, or `EventGrid`.
5262
53-
1. Declare a variable to hold the name for your Event Grid namespace. Specify a name for the namespace by replacing `<your-namespace-name>` with a value you like.
63+
1. Declare a variable to hold the name for your Event Grid namespace. Specify a name for the namespace by replacing `<your-namespace-name>` with your value.
5464
55-
```azurecli-interactive
56-
namespace="<your-namespace-name>"
57-
```
58-
2. Create a namespace. You might want to change the location where it's deployed.
65+
```azurecli-interactive
66+
namespace="<your-namespace-name>"
67+
```
5968

60-
```azurecli-interactive
61-
az eventgrid namespace create -g $resource_group -n $namespace -l eastus
62-
```
69+
1. Create a namespace. You might want to change the location where you deploy it.
70+
71+
```azurecli-interactive
72+
az eventgrid namespace create --resource-group $resource_group --name $namespace --location eastus
73+
```
6374

6475
## Create a namespace topic
6576

66-
Create a topic that's used to hold all events published to the namespace endpoint.
77+
Create a topic that holds all events published to the namespace endpoint.
6778

68-
1. Declare a variable to hold the name for your namespace topic. Specify a name for the namespace topic by replacing `<your-topic-name>` with a value you like.
79+
1. Declare a variable to hold the name for your namespace topic. Specify a name for the namespace topic by replacing `<your-topic-name>` with your value.
6980

70-
```azurecli-interactive
71-
topic="<your-topic-name>"
72-
```
73-
2. Create your namespace topic:
81+
```azurecli-interactive
82+
topic="<your-topic-name>"
83+
```
7484

75-
```azurecli-interactive
76-
az eventgrid namespace topic create -g $resource_group -n $topic --namespace-name $namespace
77-
```
85+
1. Create your namespace topic:
86+
87+
```azurecli-interactive
88+
az eventgrid namespace topic create --resource-group $resource_group --name $topic --namespace-name $namespace
89+
```
7890

7991
## Create an event subscription
8092

81-
Create an event subscription setting its delivery mode to *queue*, which supports [pull delivery](pull-delivery-overview.md). For more information on all configuration options,see the latest Event Grid control plane [REST API](/rest/api/eventgrid).
93+
Create an event subscription setting its delivery mode to *queue*, which supports [pull delivery](pull-delivery-overview.md). For more information on all configuration options, see [Azure Event Grid REST API](/rest/api/eventgrid).
8294

83-
1. Declare a variable to hold the name for an event subscription to your namespace topic. Specify a name for the event subscription by replacing `<your-event-subscription-name>` with a value you like.
95+
1. Declare a variable to hold the name for an event subscription to your namespace topic. Specify a name for the event subscription by replacing `<your-event-subscription-name>` with your value.
8496

85-
```azurecli-interactive
86-
event_subscription="<your-event-subscription-name>"
87-
```
88-
2. Create an event subscription to the namespace topic:
97+
```azurecli-interactive
98+
event_subscription="<your-event-subscription-name>"
99+
```
89100

90-
```azurecli-interactive
91-
az eventgrid namespace topic event-subscription create -g $resource_group --topic-name $topic -n $event_subscription --namespace-name $namespace --delivery-configuration "{deliveryMode:Queue,queue:{receiveLockDurationInSeconds:300,maxDeliveryCount:4,eventTimeToLive:P1D}}"
92-
```
101+
1. Create an event subscription to the namespace topic:
102+
103+
```azurecli-interactive
104+
az eventgrid namespace topic event-subscription create --resource-group $resource_group --topic-name $topic --name $event_subscription --namespace-name $namespace --delivery-configuration "{deliveryMode:Queue,queue:{receiveLockDurationInSeconds:300,maxDeliveryCount:4,eventTimeToLive:P1D}}"
105+
```
93106

94107
## Send events to your topic
95-
Now, send a sample event to the namespace topic by following steps in this section.
108+
109+
Send a sample event to the namespace topic by following steps in this section.
96110

97111
### List namespace access keys
98112

99-
1. Get the access keys associated with the namespace you created. You use one of them to authenticate when publishing events. To list your keys, you need the full namespace resource ID first. Get it by running the following command:
113+
1. Get the access keys associated with the namespace you created. You need one of them to authenticate when publishing events. To list your keys, get the full namespace resource ID. Run the following command:
100114

101-
```azurecli-interactive
102-
namespace_resource_id=$(az eventgrid namespace show -g $resource_group -n $namespace --query "id" --output tsv)
103-
```
104-
2. Get the first key from the namespace:
115+
```azurecli-interactive
116+
namespace_resource_id=$(az eventgrid namespace show --resource-group $resource_group --name $namespace --query "id" --output tsv)
117+
```
105118

106-
```azurecli-interactive
107-
key=$(az eventgrid namespace list-key -g $resource_group --namespace-name $namespace --query "key1" --output tsv)
108-
```
119+
1. Get the first key from the namespace:
120+
121+
```azurecli-interactive
122+
key=$(az eventgrid namespace list-key --resource-group $resource_group --namespace-name $namespace --query "key1" --output tsv)
123+
```
109124

110125
### Publish an event
111126

112127
1. Retrieve the namespace hostname. You use it to compose the namespace HTTP endpoint to which events are sent. The following operations were first available with API version `2023-06-01-preview`.
113128

114-
```azurecli-interactive
115-
publish_operation_uri="https://"$(az eventgrid namespace show -g $resource_group -n $namespace --query "topicsConfiguration.hostname" --output tsv)"/topics/"$topic:publish?api-version=2023-06-01-preview
116-
```
117-
2. Create a sample [CloudEvents](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/formats/json-format.md) compliant event:
129+
```azurecli-interactive
130+
publish_operation_uri="https://"$(az eventgrid namespace show -g $resource_group -n $namespace --query "topicsConfiguration.hostname" --output tsv)"/topics/"$topic:publish?api-version=2023-06-01-preview
131+
```
118132

119-
```azurecli-interactive
120-
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"}} '
121-
```
133+
1. Create a sample [CloudEvents](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/formats/json-format.md) compliant event:
122134

123-
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](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md) specifications.
124-
3. Use CURL to send the event to the topic. CURL is a utility that sends HTTP requests.
135+
```azurecli-interactive
136+
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"}} '
137+
```
125138

126-
```azurecli-interactive
127-
curl -X POST -H "Content-Type: application/cloudevents+json" -H "Authorization:SharedAccessKey $key" -d "$event" $publish_operation_uri
128-
```
139+
The `data` element is the payload of your event. Any well-formed JSON can go in this field. Properties that can go into an event are also known as *context attributes*. For more information, see [CloudEvents](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md).
140+
141+
1. Use CURL to send the event to the topic. CURL is a utility that sends HTTP requests.
142+
143+
```azurecli-interactive
144+
curl -X POST -H "Content-Type: application/cloudevents+json" -H "Authorization:SharedAccessKey $key" -d "$event" $publish_operation_uri
145+
```
129146

130147
### Receive the event
131148

132149
You receive events from Event Grid using an endpoint that refers to an event subscription.
133150

134-
1. Compose that endpoint by running the following command:
151+
1. Compose the endpoint by running the following command:
135152

136-
```azurecli-interactive
137-
receive_operation_uri="https://"$(az eventgrid namespace show -g $resource_group -n $namespace --query "topicsConfiguration.hostname" --output tsv)"/topics/"$topic/eventsubscriptions/$event_subscription:receive?api-version=2023-06-01-preview
138-
```
139-
2. Submit a request to consume the event:
153+
```azurecli-interactive
154+
receive_operation_uri="https://"$(az eventgrid namespace show --resource-group $resource_group --name $namespace --query "topicsConfiguration.hostname" --output tsv)"/topics/"$topic/eventsubscriptions/$event_subscription:receive?api-version=2023-06-01-preview
155+
```
140156

141-
```azurecli-interactive
142-
curl -X POST -H "Content-Type: application/json" -H "Authorization:SharedAccessKey $key" $receive_operation_uri
143-
```
157+
1. Submit a request to consume the event:
158+
159+
```azurecli-interactive
160+
curl -X POST -H "Content-Type: application/json" -H "Authorization:SharedAccessKey $key" $receive_operation_uri
161+
```
144162

145163
### Acknowledge an event
146164

147-
After you receive an event, you pass that event to your application for processing. Once you have successfully processed your event, you no longer need that event to be in your event subscription. To instruct Event Grid to delete the event, you **acknowledge** it using its lock token that you got on the receive operation's response.
165+
After you receive an event, you pass that event to your application for processing. After you successfully process your event, you no longer need that event to be in your event subscription. To instruct Event Grid to delete the event, you **acknowledge** it using its lock token that you got on the receive operation's response.
148166

149-
1. In the previous step, you should have received a response that includes a `brokerProperties` object with a `lockToken` property. Copy the lock token value and set it on an environment variable:
167+
1. In the previous section, you received a response that includes a `brokerProperties` object with a `lockToken` property. Copy the lock token value and set it on an environment variable:
150168

151-
```azurecli-interactive
152-
lockToken="<paste-the-lock-token-here>"
153-
```
154-
2. Now, build the acknowledge operation payload, which specifies the lock token for the event you want to be acknowledged.
169+
```azurecli-interactive
170+
lockToken="<paste-the-lock-token-here>"
171+
```
155172

156-
```azurecli-interactive
157-
acknowledge_request_payload=' { "lockTokens": ["'$lockToken'"]} '
158-
```
159-
3. Proceed with building the string with the acknowledge operation URI:
173+
1. Build the acknowledge operation payload, which specifies the lock token for the event you want to be acknowledged.
160174

161-
```azurecli-interactive
162-
acknowledge_operation_uri="https://"$(az eventgrid namespace show -g $resource_group -n $namespace --query "topicsConfiguration.hostname" --output tsv)"/topics/"$topic/eventsubscriptions/$event_subscription:acknowledge?api-version=2023-06-01-preview
163-
```
164-
4. Finally, submit a request to acknowledge the event received:
175+
```azurecli-interactive
176+
acknowledge_request_payload=' { "lockTokens": ["'$lockToken'"]} '
177+
```
165178

166-
```azurecli-interactive
167-
curl -X POST -H "Content-Type: application/json" -H "Authorization:SharedAccessKey $key" -d "$acknowledge_request_payload" $acknowledge_operation_uri
168-
```
169-
170-
If the acknowledge operation is executed before the lock token expires (300 seconds as set when we created the event subscription), you should see a response like the following example:
171-
172-
```json
173-
{"succeededLockTokens":["CiYKJDQ4NjY5MDEyLTk1OTAtNDdENS1BODdCLUYyMDczNTYxNjcyMxISChDZae43pMpE8J8ovYMSQBZS"],"failedLockTokens":[]}
174-
```
175-
176-
## Next steps
177-
To learn more about pull delivery model, see [Pull delivery overview](pull-delivery-overview.md).
179+
1. Proceed with building the string with the acknowledge operation URI:
180+
181+
```azurecli-interactive
182+
acknowledge_operation_uri="https://"$(az eventgrid namespace show -g $resource_group -n $namespace --query "topicsConfiguration.hostname" --output tsv)"/topics/"$topic/eventsubscriptions/$event_subscription:acknowledge?api-version=2023-06-01-preview
183+
```
184+
185+
1. Finally, submit a request to acknowledge the event received:
186+
187+
```azurecli-interactive
188+
curl -X POST -H "Content-Type: application/json" -H "Authorization:SharedAccessKey $key" -d "$acknowledge_request_payload" $acknowledge_operation_uri
189+
```
190+
191+
If the acknowledge operation is executed before the lock token expires (300 seconds as set when we created the event subscription), you should see a response like the following example:
192+
193+
```json
194+
{"succeededLockTokens":["CiYKJDQ4NjY5MDEyLTk1OTAtNDdENS1BODdCLUYyMDczNTYxNjcyMxISChDZae43pMpE8J8ovYMSQBZS"],"failedLockTokens":[]}
195+
```
196+
197+
## Next step
198+
199+
To learn more about pull delivery model, see [Pull delivery with HTTP](pull-delivery-overview.md).

0 commit comments

Comments
 (0)