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
Copy file name to clipboardExpand all lines: articles/iot-operations/connect-to-cloud/tutorial-connect-event-grid.md
+69-14Lines changed: 69 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ ms.subservice: mq
7
7
ms.custom: devx-track-azurecli
8
8
ms.author: patricka
9
9
ms.topic: tutorial
10
-
ms.date: 11/15/2023
10
+
ms.date: 02/28/2024
11
11
12
12
#CustomerIntent: As an operator, I want to configure IoT MQ to bridge to Azure Event Grid MQTT broker PaaS so that I can process my IoT data at the edge and in the cloud.
13
13
---
@@ -22,12 +22,47 @@ In this tutorial, you learn how to configure IoT MQ for bi-directional MQTT brid
Set environment variables for the rest of the setup. Replace values in `<>` with valid values or names of your choice. A new Azure Event Grid namespace and topic space are created in your Azure subscription based on the names you provide:
35
+
36
+
```azurecli
37
+
# For this tutorial, the steps assume the IoT Operations cluster and the Event Grid
38
+
# are in the same subscription, resource group, and location.
39
+
40
+
# Name of the resource group of Azure Event Grid and IoT Operations cluster
41
+
export RESOURCE_GROUP=<RESOURCE_GROUP_NAME>
42
+
43
+
# Azure region of Azure Event Grid and IoT Operations cluster
# Subscription ID of Azure Event Grid and IoT Operations cluster
53
+
export SUBSCRIPTION_ID=<SUBSCRIPTION_ID>
54
+
```
55
+
25
56
## Create Event Grid namespace with MQTT broker enabled
26
57
27
-
[Create Event Grid namespace](../../event-grid/create-view-manage-namespaces.md) with Azure CLI. Replace `<EG_NAME>`, `<RESOURCE_GROUP>`, and `<LOCATION>` with your own values. The location should be the same as the one you used to deploy Azure IoT Operations.
58
+
[Create Event Grid namespace](../../event-grid/create-view-manage-namespaces.md) with Azure CLI. The location should be the same as the one you used to deploy Azure IoT Operations.
By setting the `topic-spaces-configuration`, this command creates a namespace with:
@@ -39,20 +74,30 @@ The max client sessions option allows IoT MQ to spawn multiple instances and sti
39
74
40
75
## Create a topic space
41
76
42
-
In the Event Grid namespace, create a topic space named `tutorial` with a topic template `telemetry/#`. Replace `<EG_NAME>` and `<RESOURCE_GROUP>` with your own values.
77
+
In the Event Grid namespace, create a topic space named `tutorial` with a topic template `telemetry/#`.
By using the `#` wildcard in the topic template, you can publish to any topic under the `telemetry` topic space. For example, `telemetry/temperature` or `telemetry/humidity`.
49
88
50
89
## Give IoT MQ access to the Event Grid topic space
51
90
52
-
Using `az k8s-extension show`, find the principal ID for the Azure IoT MQ Arc extension.
91
+
Using `az k8s-extension show`, find the principal ID for the Azure IoT MQ Arc extension. The command stores the principal ID in a variable for later use.
53
92
54
93
```azurecli
55
-
az k8s-extension show --resource-group <RESOURCE_GROUP> --cluster-name <CLUSTER_NAME> --name mq --cluster-type connectedClusters --query identity.principalId -o tsv
94
+
export PRINCIPAL_ID=$(az k8s-extension show \
95
+
--resource-group $RESOURCE_GROUP \
96
+
--cluster-name $CLUSTER_NAME \
97
+
--name mq \
98
+
--cluster-type connectedClusters \
99
+
--query identity.principalId -o tsv)
100
+
echo $PRINCIPAL_ID
56
101
```
57
102
58
103
Take note of the output value for `identity.principalId`, which is a GUID value with the following format:
@@ -61,29 +106,39 @@ Take note of the output value for `identity.principalId`, which is a GUID value
61
106
d84481ae-9181-xxxx-xxxx-xxxxxxxxxxxx
62
107
```
63
108
64
-
Then, use Azure CLI to assign publisher and subscriber roles to IoT MQ for the topic space you created. Replace `<MQ_ID>` with the principal ID you found in the previous step, and replace `<SUBSCRIPTION_ID>`, `<RESOURCE_GROUP>`, `<EG_NAME>` with your values matching the Event Grid namespace you created.
109
+
Then, use Azure CLI to assign publisher and subscriber roles to IoT MQ for the topic space you created.
65
110
66
-
Assigning the publisher role:
111
+
Assign the publisher role:
67
112
68
113
```azurecli
69
-
az role assignment create --assignee <MQ_ID> --role "EventGrid TopicSpaces Publisher" --scope /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.EventGrid/namespaces/<EG_NAME>/topicSpaces/tutorial
> The scope matches the `id` of the topic space you created with `az eventgrid namespace topic-space create` in the previous step, and you can find it in the output of the command.
80
131
81
132
## Event Grid MQTT broker hostname
82
133
83
-
Use Azure CLI to get the Event Grid MQTT broker hostname. Replace `<EG_NAME>` and `<RESOURCE_GROUP>` with your own values.
134
+
Use Azure CLI to get the Event Grid MQTT broker hostname.
84
135
85
136
```azurecli
86
-
az eventgrid namespace show -g <RESOURCE_GROUP> -n <EG_NAME> --query topicSpacesConfiguration.hostname -o tsv
137
+
az eventgrid namespace show \
138
+
--resource-group $RESOURCE_GROUP \
139
+
--namespace-name $EVENT_GRID_NAMESPACE \
140
+
--query topicSpacesConfiguration.hostname \
141
+
-o tsv
87
142
```
88
143
89
144
Take note of the output value for `topicSpacesConfiguration.hostname` that is a hostname value that looks like:
0 commit comments