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
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.
#customer intent: As a developer, I want to use the pull delivery model to publish and consume events using Azure Event Grid.
9
10
---
10
11
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
12
13
13
-
This article provides a quick introduction to 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.
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.
14
15
15
16
For sample code that uses the data plane SDKs, see these resources:
16
17
@@ -28,20 +29,21 @@ For more information about the pull delivery model, see [Azure Event Grid namesp
28
29
29
30
## Create a resource group
30
31
31
-
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.
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.
32
33
33
34
The general steps to use Cloud Shell to run commands are:
34
35
35
36
- Select **Open Cloud Shell** to see an Azure Cloud Shell window on the right pane.
36
37
- Copy the command and paste into the Azure Cloud Shell window.
37
38
- Press ENTER to run the command.
38
39
39
-
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.
40
41
41
42
```azurecli-interactive
42
43
resource_group="<your-resource-group-name>"
43
44
```
44
-
1. 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.
45
47
46
48
```azurecli-interactive
47
49
az group create --name $resource_group --location eastus
@@ -55,135 +57,143 @@ An Event Grid namespace provides a user-defined endpoint to which you post your
55
57
56
58
- It should be between 3-50 characters.
57
59
- It should be regionally unique.
58
-
- Only allowed characters are a-z, A-Z, 0-9 and -
60
+
- Only allowed characters are: a-z, A-Z, 0-9, and -
59
61
- It shouldn't start with reserved key word prefixes like `Microsoft`, `System`, or `EventGrid`.
60
62
61
-
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.
64
+
65
+
```azurecli-interactive
66
+
namespace="<your-namespace-name>"
67
+
```
62
68
63
-
```azurecli-interactive
64
-
namespace="<your-namespace-name>"
65
-
```
66
69
1. Create a namespace. You might want to change the location where you deploy it.
67
70
68
-
```azurecli-interactive
69
-
az eventgrid namespace create --resource-group $resource_group --name $namespace --location eastus
70
-
```
71
+
```azurecli-interactive
72
+
az eventgrid namespace create --resource-group $resource_group --name $namespace --location eastus
73
+
```
71
74
72
75
## Create a namespace topic
73
76
74
-
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.
75
78
76
-
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.
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).
90
94
91
-
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.
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.
104
110
105
111
### List namespace access keys
106
112
107
-
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:
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`.
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).
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).
133
140
134
141
1. Use CURL to send the event to the topic. CURL is a utility that sends HTTP requests.
curl -X POST -H "Content-Type: application/json" -H "Authorization:SharedAccessKey $key" $receive_operation_uri
154
-
```
159
+
```azurecli-interactive
160
+
curl -X POST -H "Content-Type: application/json" -H "Authorization:SharedAccessKey $key" $receive_operation_uri
161
+
```
155
162
156
163
### Acknowledge an event
157
164
158
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.
159
166
160
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:
161
168
162
-
```azurecli-interactive
163
-
lockToken="<paste-the-lock-token-here>"
164
-
```
165
-
1. 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
+
```
172
+
173
+
1. Build the acknowledge operation payload, which specifies the lock token for the event you want to be acknowledged.
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:
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:
0 commit comments