Skip to content

Commit 0108b20

Browse files
Freshness.
1 parent d92f5b7 commit 0108b20

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

articles/event-grid/mqtt-publish-and-subscribe-cli.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
---
2-
title: 'Quickstart: Publish and subscribe on an MQTT topic by using the CLI'
2+
title: 'Quickstart: Publish on an MQTT topic by using the CLI'
33
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
77
- devx-track-azurecli
88
- ignite-2023
9-
ms.date: 11/15/2023
9+
ms.date: 06/24/2025
1010
author: george-guirguis
1111
ms.author: geguirgu
1212
ms.subservice: mqtt
13+
#customer intent: As a developer, I want to use the Azure Event Grid MQTT broker for messaging of apps and IoT.
1314
---
1415

1516
# Quickstart: Publish and subscribe to MQTT messages on an Event Grid namespace with the Azure CLI
1617

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.
18+
In this quickstart, you use the Azure Event Grid MQTT broker feature to support messaging by using the MQTT protocol. Clients, including 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.
1819

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

@@ -27,11 +28,11 @@ If you don't have an [Azure subscription](/azure/guides/developer/azure-develope
2728

2829
## Prerequisites
2930

30-
- If you're new to Event Grid, read through the [Event Grid overview](../event-grid/overview.md) before you start this tutorial.
31+
- If you're new to Event Grid, see the [Event Grid overview](../event-grid/overview.md) before you start this tutorial.
3132
- Register the Event Grid resource provider according to the steps in [Register the Event Grid resource provider](../event-grid/custom-event-quickstart-portal.md#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.
33+
- Make sure that port 8883 is open in your firewall. This tutorial uses the MQTT protocol, which communicates over port 8883. This port might be blocked in some corporate and educational network environments.
3334
- Use the Bash environment in [Azure Cloud Shell](../cloud-shell/overview.md). For more information, see [Get started with Azure Cloud Shell](../cloud-shell/quickstart.md).
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 prefer to run CLI reference commands locally, [install](/cli/azure/install-azure-cli) the Azure CLI. If you run 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).
3536
- 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 [Authenticate to Azure using Azure CLI](/cli/azure/authenticate-azure-cli).
3637
- When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see [Manage Azure CLI Extensions](/cli/azure/azure-cli-extensions-overview).
3738
- 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).
@@ -43,49 +44,50 @@ If you don't have an [Azure subscription](/azure/guides/developer/azure-develope
4344

4445
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.
4546

46-
After a successful installation by using the step CLI, open a command prompt in your user profile folder (Win+R type %USERPROFILE%).
47+
After a successful installation by using the step CLI, open a Command Prompt window in your user profile folder (`Win+R type %USERPROFILE%`).
4748

4849
1. To create root and intermediate certificates, run the following command. Remember the password, which you need to use in the next step.
4950

5051
```powershell
5152
step ca init --deployment-type standalone --name MqttAppSamplesCA --dns localhost --address 127.0.0.1:443 --provisioner MqttAppSamplesCAProvisioner
5253
```
5354
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.
55+
1. To create a certificate for the client, use the certificate authority (CA) files generated. Make sure to use the correct path for the cert and secrets files in the command.
5556
5657
```powershell
5758
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
5859
```
5960
6061
1. To view the thumbprint, run the step command.
61-
62-
```powershell
63-
step certificate fingerprint client1-authnID.pem
64-
```
62+
63+
```powershell
64+
step certificate fingerprint client1-authnID.pem
65+
```
6566

6667
## Create a namespace
6768

68-
Use the command to create a namespace. Update the command with your resource group and a namespace name.
69+
Use this command to create a namespace. Update the command with your resource group and a namespace name.
6970

7071
```azurecli-interactive
7172
az eventgrid namespace create --resource-group {Resource Group} --name {Namespace Name} --topic-spaces-configuration "{state:Enabled}"
7273
```
7374

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).
75+
To keep this quickstart simple, create a namespace with minimal properties. For more information about network, security, and settings on other tabs, see [Create and manage namespaces](create-view-manage-namespaces.md).
7576

7677
## Create clients
7778

78-
Use the command to create the client. Update the command with your resource group and a namespace name.
79+
Use this command to create the client. Update the command with your resource group and a namespace name.
7980

8081
```azurecli-interactive
8182
az eventgrid namespace client create --resource-group {Resource Group} --namespace-name {Namespace Name} --name {Client Name} --authentication-name client1-authnID --client-certificate-authentication "{validationScheme:ThumbprintMatch,allowed-thumbprints:[Client Thumbprint]}"
8283
```
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).
84+
85+
- To keep this quickstart simple, 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).
86+
- For this exercise, 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).
8587

8688
## Create topic spaces
8789

88-
Use the command to create the topic space. Update the command with your resource group, namespace name, and topic space name.
90+
Use this command to create the topic space. Update the command with your resource group, namespace name, and topic space name.
8991

9092
```azurecli-interactive
9193
az eventgrid namespace topic-space create --resource-group {Resource Group} --namespace-name {Namespace Name} --name {Topicspace Name} --topic-templates ['contosotopics/topic1']
@@ -99,20 +101,20 @@ Use the `az eventgrid` command to create the first permission binding for publis
99101
az eventgrid namespace permission-binding create --resource-group {Resource Group} --namespace-name {Namespace Name} --name {Permission Binding Name} --client-group-name '$all' --permission publisher --topic-space-name {Topicspace Name}
100102
```
101103

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.
104+
Use this 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.
103105

104106
```azurecli-interactive
105107
az eventgrid namespace permission-binding create --resource-group {Resource Group} --namespace-name {Namespace Name} --name {Name of second Permission Binding} --client-group-name '$all' --permission subscriber --topic-space-name {Topicspace Name}
106108
```
107109

108110
## Publish and subscribe to MQTT messages
109111

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.
112+
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 modify the code for your requirements and run it in Visual Studio or another design tool.
111113

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.)
114+
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.
113115

114116
> [!NOTE]
115-
>The following sample code is for demonstration purposes only and isn't intended for production use.
117+
> The following sample code is for demonstration purposes only and isn't intended for production use.
116118
117119
### Sample C# code to connect a client, publish, and subscribe to an MQTT message on a topic
118120

0 commit comments

Comments
 (0)