In this example of an MQTT request, you will connect to a public broker, subscribe to topics, publish messages, and visualize the response.
In Postman, select New > MQTT to create a new request. (In the Postman desktop app, you can also select ⌘+N or Ctrl+N, then select MQTT).
To connect to an MQTT service, you need a broker URL. This example uses the public broker test.mosquitto.org
. You can also use any other public broker or a broker hosted on your local machine.
test.mosquitto.org
as the request URL.A message in the response area indicates that you're connected to the broker.
If you're using the Postman web app, use the Postman Desktop Agent to connect to an MQTT broker. See About the Postman Agent for more information.
While connected to the broker, select the Topics tab. This enables you to create, document, and subscribe to multiple topics.
my-toys
as the topic name.A message appears in the response area indicating that you're subscribed to the topic.
You can use the Message tab to compose and send messages to the broker.
{"age": 2, "number of toys": 5}
as the message.my-toys
as the topic name.An outgoing message appears in the response area indicating that the message was published. Because you have already subscribed to the topic, my-toys
, you will also see an incoming message with the same body. Go ahead and send a few more messages counting the number of toys you had growing up.
Now that you've subscribed to a topic and published a few messages, you can use the Postman Visualizer to view the messages in a more comprehensible format.
age
field visualized as a line chart.The visualization changes in real time as you receive newer messages for the same topic.
Try subscribing to multiple topics at once and publishing messages to them.
Last modified: 2024/05/30