Skip to content

Commit a4e0b35

Browse files
committed
Added more content
1 parent 8b9b7ed commit a4e0b35

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

articles/event-grid/mqtt-routing-to-azure-functions-cli.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,48 @@ You use this Azure function as an event handler for a topic's subscription later
5151
5252
## Create an Event Grid topic (custom topic)
5353

54+
In this step, you create an Event Grid topic.
55+
56+
1. Copy and paste the script to an editor.
57+
1. Replace the following values.
58+
1. Select **Open Cloud Shell**.
59+
1. Switch from **PowerShell** to **Bash** (in the upper-left corner of the Cloud Shell window).
60+
1. Copy and paste the script from the editor to Cloud Shell and run the script.
61+
62+
The script creates an Azure resource group and an Event Grid custom topic in it. Later in this tutorial, you configure routing for an Event Grid namespace so that the events or messages sent to the namespace are routed to the custom topic and then to the Azure function via subscription to the topic.
63+
64+
| Placeholder | Description |
65+
| ----------- | ----------- |
66+
|`RESOURCEGROUPNAME` | Name of the resource group to be created. |
67+
| `REGION` | Region in which you want to create the resource group and the custom topic. |
68+
| `TOPICNAME` | Name of the custom topic to be created. |
69+
70+
The script uses the [`az eventgrid topic create`](/cli/azure/eventgrid/topic#az-eventgrid-topic-create) command to create an Event Grid topic or custom topic. The schema type is specified as the cloud event schema.
71+
5472
```azurecli-interactive
5573
rgName="RESOURCEGROUPNAME"
5674
location="REGION"
5775
topicName="TOPICNAME"
5876
5977
az group create -n $rgName -l $location
78+
6079
az eventgrid topic create --name $topicName -l $location -g $rgName --input-schema cloudeventschemav1_0
6180
```
6281

6382
> [!NOTE]
6483
> Use **Cloud event schema** everywhere in this tutorial.
6584
6685
## Add a subscription to the topic using the function
67-
In this step, you create a subscription to the Event Grid topic using the Azure function you created earlier.
86+
87+
In this step, you create a subscription to the custom topic using the Azure function you created earlier.
88+
89+
Replace the following values and run the script in the Cloud Shell. The script uses the [`az eventgrid event-subscription create`](/cli/azure/eventgrid/event-subscription#az-eventgrid-event-subscription-create) command to create an Azure function subscription to the custom topic. In the command, source ID is the topic's resource ID and endpoint is the function's resource ID. The endpoint type is set to Azure function and event delivery schema is specified as the cloud event schema.
90+
91+
| Placeholder | Description |
92+
| ----------- | ----------- |
93+
|`FUNCTIONRESOURCEGROUP` | Name of the resource group that has the Azure Functions app. |
94+
| `FUNCTIONSAPPNAME` | Name of the Azure Functions app. |
95+
| `FUNCTIONNAME` | Name of the Azure function. |
6896

6997
```azurecli-interactive
7098
funcAppRgName="FUNCTIONRESOURCEGROUP"
@@ -90,28 +118,42 @@ Follow instructions from [Quickstart: Publish and subscribe to MQTT messages on
90118

91119
## Enable managed identity for the namespace
92120

93-
Enable system-assigned managed identity for the Event Grid namespace.
121+
Replace the following value and run the script to enable system-assigned managed identity for the Event Grid namespace.
122+
123+
| Placeholder | Description |
124+
| ----------- | ----------- |
125+
|`EVENTGRIDNAMESPACENAME` | Name of the Event Grid namespace. |
126+
127+
The script uses the [`az eventgrid namespace update`](/cli/azure/eventgrid/namespace#az-eventgrid-namespace-update) command with `identity` set to `SystemAssigned` identity.
128+
94129

95130
```azurecli-interactive
96131
nsName="EVENTGRIDNAMESPACENAME"
97132
az eventgrid namespace update -g $rgName -n $nsName --topic-spaces-configuration "{state:Enabled}" --identity "{type:SystemAssigned}"
98133
```
99134

100-
Then, grant identity the **send** permission to the Event Grid custom topic you created earlier so that it can route message to the custom topic. You do so by adding the managed identity to the **Event Grid Data Sender** role on the custom topic.
135+
Then, grant namespace's managed identity the **send** permission on the Event Grid custom topic you created earlier so that the namespace can send or route messages to the custom topic. You do so by adding the managed identity to the **Event Grid Data Sender** role on the custom topic.
136+
101137

102138
```azurecli-interactive
103139
egNamespaceServicePrincipalObjectID=$(az ad sp list --display-name $nsName --query [].id -o tsv)
104140
topicResourceId=$(az eventgrid topic show --name $topicName -g $rgName --query id --output tsv)
105141
az role assignment create --assignee $egNamespaceServicePrincipalObjectID --role "EventGrid Data Sender" --scope $topicResourceId
106142
```
107143

144+
The script uses the [`az role assignment create`](/cli/azure/role/assignment#az-role-assignment-create) command with the IDs of namespace's managed identity and the custom topic, and assigns **Event Grid Data Sender** role to the namespace's managed identity on the custom topic.
145+
146+
108147
## Configure routing messages to Azure function via custom topic
148+
109149
In this step, you configure routing for the Event Grid namespace so that the messages it receives are routed to the custom topic you created.
110150

111151
```azurecli-interactive
112152
az eventgrid namespace update -g $rgName -n $nsName --topic-spaces-configuration "{state:Enabled,'routeTopicResourceId':$topicResourceId,'routingIdentityInfo':{type:SystemAssigned}}"
113153
```
114154

155+
The script uses the [`az eventgrid namespace update`](/cli/azure/eventgrid/namespace#az-eventgrid-namespace-update) command to set the routing topic and the type of managed identity to use to route events to the topic.
156+
115157
## Send test MQTT messages using MQTTX
116158
Send test MQTT messages to the namespace and confirm that the function receives them.
117159

0 commit comments

Comments
 (0)