Skip to content

Commit f136dee

Browse files
authored
Merge pull request #260401 from paulth1/three-mqtt-articles
[AQ] edit pass: Three mqtt articles
2 parents 7066d56 + e1ce78d commit f136dee

File tree

3 files changed

+152
-139
lines changed

3 files changed

+152
-139
lines changed
Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: 'Quickstart: Publish and subscribe on an MQTT topic using CLI'
3-
description: 'Quickstart guide to use Azure Event Grid’s MQTT broker feature and Azure CLI to publish and subscribe MQTT messages on a topic'
2+
title: 'Quickstart: Publish and subscribe on an MQTT topic by using the CLI'
3+
description: Quickstart guide to use the Azure Event Grid MQTT broker feature and the Azure CLI to publish and subscribe to MQTT messages on a topic.
44
ms.topic: quickstart
55
ms.custom:
66
- build-2023
@@ -12,113 +12,112 @@ ms.author: geguirgu
1212
ms.subservice: mqtt
1313
---
1414

15-
# Quickstart: Publish and subscribe to MQTT messages on Event Grid Namespace with Azure CLI
15+
# Quickstart: Publish and subscribe to MQTT messages on an Event Grid namespace with the Azure CLI
1616

17-
Azure Event Grid’s MQTT broker feature supports messaging using the MQTT protocol. Clients (both devices and cloud applications) can publish and subscribe MQTT messages over flexible hierarchical topics for scenarios such as high scale broadcast, and command & control.
17+
The Azure Event Grid MQTT broker feature supports messaging by using the MQTT protocol. Clients (both devices and cloud applications) can publish and subscribe to MQTT messages over flexible hierarchical topics for scenarios such as high-scale broadcast and command and control.
1818

19+
In this article, you use the Azure CLI to:
1920

20-
In this article, you use the Azure CLI to do the following tasks:
21-
1. Create an Event Grid namespace and enable MQTT broker
22-
2. Create subresources such as clients, client groups, and topic spaces
23-
3. Grant clients access to publish and subscribe to topic spaces
24-
4. Publish and receive MQTT messages
21+
- Create an Event Grid namespace and enable the MQTT broker.
22+
- Create subresources such as clients, client groups, and topic spaces.
23+
- Grant clients access to publish and subscribe to topic spaces.
24+
- Publish and receive MQTT messages.
25+
26+
If you don't have an [Azure subscription](/azure/guides/developer/azure-developer-guide#understanding-accounts-subscriptions-and-billing), create an [Azure free account](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio) before you begin.
2527

2628
## Prerequisites
27-
- If you don't have an [Azure subscription](/azure/guides/developer/azure-developer-guide#understanding-accounts-subscriptions-and-billing), create an [Azure free account](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio) before you begin.
28-
- If you're new to Azure Event Grid, read through [Event Grid overview](/azure/event-grid/overview) before starting this tutorial.
29-
- Register the Event Grid resource provider as per [Register the Event Grid resource provider](/azure/event-grid/custom-event-quickstart-portal#register-the-event-grid-resource-provider).
30-
- Make sure that port 8883 is open in your firewall. The sample in this tutorial uses MQTT protocol, which communicates over port 8883. This port might be blocked in some corporate and educational network environments.
29+
30+
- If you're new to Event Grid, read through the [Event Grid overview](/azure/event-grid/overview) before you start this tutorial.
31+
- Register the Event Grid resource provider according to the steps in [Register the Event Grid resource provider](/azure/event-grid/custom-event-quickstart-portal#register-the-event-grid-resource-provider).
32+
- Make sure that port 8883 is open in your firewall. The sample in this tutorial uses the MQTT protocol, which communicates over port 8883. This port might be blocked in some corporate and educational network environments.
3133
- Use the Bash environment in [Azure Cloud Shell](/azure/cloud-shell/overview). For more information, see [Quickstart for Bash in Azure Cloud Shell](/azure/cloud-shell/quickstart).
32-
- If you prefer to run CLI reference commands locally, [install](/cli/azure/install-azure-cli) the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see [How to run the Azure CLI in a Docker container](/cli/azure/run-azure-cli-docker).
33-
- If you're using a local installation, sign in to the Azure CLI by using the [az login](/cli/azure/reference-index#az-login) command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see [Sign in with the Azure CLI](/cli/azure/authenticate-azure-cli).
34+
- If you prefer to run CLI reference commands locally, [install](/cli/azure/install-azure-cli) the Azure CLI. If you're running on Windows or macOS, consider running the Azure CLI in a Docker container. For more information, see [Run the Azure CLI in a Docker container](/cli/azure/run-azure-cli-docker).
35+
- If you're using a local installation, sign in to the Azure CLI by using the [az login](/cli/azure/reference-index#az-login) command. To finish the authentication process, follow the steps that appear in your terminal. For other sign-in options, see [Sign in with the Azure CLI](/cli/azure/authenticate-azure-cli).
3436
- When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see [Use extensions with the Azure CLI](/cli/azure/azure-cli-extensions-overview).
3537
- Run [az version](/cli/azure/reference-index?#az-version) to find the version and dependent libraries that are installed. To upgrade to the latest version, run [az upgrade](/cli/azure/reference-index?#az-upgrade).
36-
- This article requires version 2.53.1 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
38+
- This article requires version 2.53.1 or later of the Azure CLI. If you're using Azure Cloud Shell, the latest version is already installed.
3739
- You need an X.509 client certificate to generate the thumbprint and authenticate the client connection.
38-
- Review the Event Grid namespace [CLI documentation](/cli/azure/eventgrid/namespace)
40+
- Review the Event Grid namespace [CLI documentation](/cli/azure/eventgrid/namespace).
3941

40-
## Generate sample client certificate and thumbprint
41-
If you don't already have a certificate, you can create a sample certificate using the [step CLI](https://smallstep.com/docs/step-cli/installation/). Consider installing manually for Windows.
42+
## Generate a sample client certificate and thumbprint
4243

43-
After a successful installation of Step, you should open a command prompt in your user profile folder (Win+R type %USERPROFILE%).
44+
If you don't already have a certificate, you can create a sample certificate by using the [step CLI](https://smallstep.com/docs/step-cli/installation/). Consider installing manually for Windows.
4445

45-
1. To create root and intermediate certificates, run the following command. Remember the password, which needs to be used in the next step.
46+
After a successful installation by using the step CLI, open a command prompt in your user profile folder (Win+R type %USERPROFILE%).
4647

47-
```powershell
48-
step ca init --deployment-type standalone --name MqttAppSamplesCA --dns localhost --address 127.0.0.1:443 --provisioner MqttAppSamplesCAProvisioner
49-
```
48+
1. To create root and intermediate certificates, run the following command. Remember the password, which you need to use in the next step.
5049

51-
2. Using the CA files generated to create certificate for the client. Ensure to use the correct path for the cert and secrets files in the command.
50+
```powershell
51+
step ca init --deployment-type standalone --name MqttAppSamplesCA --dns localhost --address 127.0.0.1:443 --provisioner MqttAppSamplesCAProvisioner
52+
```
5253
53-
```powershell
54-
step certificate create client1-authnID client1-authnID.pem client1-authnID.key --ca .step/certs/intermediate_ca.crt --ca-key .step/secrets/intermediate_ca_key --no-password --insecure --not-after 2400h
55-
```
54+
1. Use the certificate authority (CA) files generated to create a certificate for the client. Make sure to use the correct path for the cert and secrets files in the command.
5655
57-
3. To view the thumbprint, run the Step command.
56+
```powershell
57+
step certificate create client1-authnID client1-authnID.pem client1-authnID.key --ca .step/certs/intermediate_ca.crt --ca-key .step/secrets/intermediate_ca_key --no-password --insecure --not-after 2400h
58+
```
5859
59-
```powershell
60-
step certificate fingerprint client1-authnID.pem
61-
```
60+
1. To view the thumbprint, run the step command.
61+
62+
```powershell
63+
step certificate fingerprint client1-authnID.pem
64+
```
6265
63-
## Create a Namespace
66+
## Create a namespace
6467
65-
Use the command to create a namespace. Update the command with your Resource group, and a Namespace name.
68+
Use the command to create a namespace. Update the command with your resource group and a namespace name.
6669
6770
```azurecli-interactive
6871
az eventgrid namespace create -g {Resource Group} -n {Namespace Name} --topic-spaces-configuration "{state:Enabled}"
6972
```
7073

71-
> [!NOTE]
72-
> To keep the QuickStart simple, you'll create a namespace with minimal properties. For detailed steps about configuring network, security, and other settings on other pages of the wizard, see [create and manage namespaces](create-view-manage-namespaces.md).
74+
To keep the quickstart simple, you create a namespace with minimal properties. For detailed steps about configuring network, security, and other settings on other pages of the wizard, see [Create and manage namespaces](create-view-manage-namespaces.md).
7375

7476
## Create clients
7577

76-
Use the command to create the client. Update the command with your Resource group, and a Namespace name.
78+
Use the command to create the client. Update the command with your resource group and a namespace name.
7779

7880
```azurecli-interactive
7981
az eventgrid namespace client create -g {Resource Group} --namespace-name {Namespace Name} -n {Client Name} --authentication-name client1-authnID --client-certificate-authentication "{validationScheme:ThumbprintMatch,allowed-thumbprints:[Client Thumbprint]}"
8082
```
81-
82-
> [!NOTE]
83-
> - To keep the QuickStart simple, you'll be using Thumbprint match for authentication. For detailed steps on using X.509 CA certificate chain for client authentication, see [client authentication using certificate chain](./mqtt-certificate-chain-client-authentication.md).
84-
> - Also for this exercise, we use the default $all client group, which includes all the clients in the namespace. To learn more about creating custom client groups using client attributes, see [client groups](mqtt-client-groups.md) document.
83+
- To keep the quickstart simple, you use thumbprint match for authentication. For steps on how to use the X.509 CA certificate chain for client authentication, see [Client authentication using certificate chain](./mqtt-certificate-chain-client-authentication.md).
84+
- For this exercise, we use the default `$all client` group, which includes all the clients in the namespace. To learn more about creating custom client groups by using client attributes, see [Client groups](mqtt-client-groups.md).
8585

8686
## Create topic spaces
8787

88-
Use the command to create the topic space. Update the command with your Resource group, namespace name, and a topic space name.
88+
Use the command to create the topic space. Update the command with your resource group, namespace name, and topic space name.
8989

9090
```azurecli-interactive
9191
az eventgrid namespace topic-space create -g {Resource Group} --namespace-name {Namespace Name} -n {Topicspace Name} --topic-templates ['contosotopics/topic1']
9292
```
9393

94-
## Create PermissionBindings
94+
## Create permission bindings
9595

96-
Use the az resource command to create the first permission binding for publisher permission. Update the command with your Resource group, namespace name, and a permission binding name.
96+
Use the `az resource` command to create the first permission binding for publisher permission. Update the command with your resource group, namespace name, and permission binding name.
9797

9898
```azurecli-interactive
9999
az eventgrid namespace permission-binding create -g {Resource Group} --namespace-name {Namespace Name} -n {Permission Binding Name} --client-group-name '$all' --permission publisher --topic-space-name {Topicspace Name}
100100
```
101101

102-
Use the command to create the second permission binding. Update the command with your Resource group, namespace name and a permission binding name. This permission binding is for subscriber.
102+
Use the command to create the second permission binding. Update the command with your resource group, namespace name, and permission binding name. This permission binding is for subscribers.
103103

104104
```azurecli-interactive
105105
az eventgrid namespace permission-binding create -g {Resource Group} --namespace-name {Namespace Name} -n {Name of second Permission Binding} --client-group-name '$all' --permission publisher --topic-space-name {Topicspace Name}
106106
```
107107

108-
## Publish and subscribe MQTT messages
108+
## Publish and subscribe to MQTT messages
109109

110-
The following sample code is a simple .NET publisher that attempts to connect, and publish to a namespace, and subscribes to the MQTT topic. You can use the code to modify per your requirement and run the code in Visual Studio or any of your favorite tools.
110+
The following sample code is a simple .NET publisher that attempts to connect and publish to a namespace and subscribes to the MQTT topic. You can use the code to modify according to your requirement and run the code in Visual Studio or any of your favorite tools.
111111

112-
You need to install the MQTTnet package (version 4.1.4.563) from NuGet to run this code.
113-
(In Visual Studio, right click on the project name in Solution Explorer, go to Manage NuGet packages, search for MQTTnet. Select MQTTnet package and install.)
112+
You need to install the MQTTnet package (version 4.1.4.563) from NuGet to run this code. (In Visual Studio, right-click the project name in Solution Explorer, go to **Manage NuGet packages**, and search for **MQTTnet**. Select **MQTTnet package** and install.)
114113

115114
> [!NOTE]
116-
>The following sample code is only for demonstration purposes and is not intended for production use.
115+
>The following sample code is for demonstration purposes only and isn't intended for production use.
117116
118-
**Sample C# code to connect a client, publish/subscribe MQTT message on a topic**
117+
### Sample C# code to connect a client, publish, and subscribe to an MQTT message on a topic
119118

120119
> [!IMPORTANT]
121-
> Please update the client certificate and key pem file paths depending on location of your client certificate files. Also, ensure the client authentication name, topic information match with your configuration.
120+
> Update the client certificate and key pem file paths depending on the location of your client certificate files. Also, ensure that the client authentication name and topic information match with your configuration.
122121
123122
```csharp
124123
using MQTTnet.Client;
@@ -162,8 +161,9 @@ while (true)
162161

163162
```
164163

165-
You can replicate and modify the same code for multiple clients to perform publish / subscribe among the clients.
164+
You can replicate and modify the same code for multiple clients to publish and subscribe among the clients.
166165

167166
## Next steps
168-
- [Route MQTT messages to Event Hubs](mqtt-routing-to-event-hubs-cli.md)
169-
- For code samples, go to [this repository.](https://github.com/Azure-Samples/MqttApplicationSamples/tree/main)
167+
168+
- [Route MQTT messages to Event Hubs](mqtt-routing-to-event-hubs-cli.md).
169+
- For code samples, go to [this GitHub repository](https://github.com/Azure-Samples/MqttApplicationSamples/tree/main).

0 commit comments

Comments
 (0)