Movatterモバイル変換


[0]ホーム

URL:


Creating your first MQTT request

In this example of an MQTT request, you will connect to a public broker, subscribe to topics, publish messages, and visualize the response.

Create an MQTT request

In Postman, clickNew and selectMQTT as the request type.

Create new request

Alternatively, clickAdd iconAdd next to an open tab. You can switch your request type by clicking the request icon next to the request name.

Switch request type

Connect to a broker with Postman

To connect to an MQTT service, you need a broker URL. This example uses the public brokertest.mosquitto.org. You can also use any other public broker or a broker hosted on your local machine.

  1. Entertest.mosquitto.org as the requestURL.
  2. ClickConnect to connect to the broker.

A message in the response area indicates that you’re connected to the broker.

Connect to a broker

If you’re using the Postman web app, use the Postman Desktop Agent to connect to an MQTT broker. SeeAbout the Postman Agent for more information.

Subscribe to topics

While connected to the broker, select theTopics tab. This enables you to create, document, and subscribe to multiple topics.

  1. In theTopics column, entermy-toys as the topic name.
  2. SelectSubscribe to subscribe to the topic.

A message appears in the response area indicating that you’re subscribed to the topic.

Subscribe to a topic

Publish messages

You can use theMessage tab to compose and send messages to the broker.

  1. Select theMessage tab and enter{"age": 2, "number of toys": 5} as the message.
  2. Entermy-toys as the topic name.
  3. SelectSend to publish the message.

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.

Subscribe to a topic

Visualize the response

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.

  1. Switch to theVisualization tab in the response area. You’ll see the messages for theage field visualized as a line chart.
  2. Select the field name dropdown list to select the field you want to visualize.
  3. SelectAdd iconAdd to add more fields to the chart and view the changes in the values.
  4. Select theChart icon icon next to any of the field names to change the chart type.

The visualization changes in real time as you receive newer messages for the same topic.

Visualization

Next step

Try subscribing to multiple topics at once and publishing messages to them.

Last modified: 2025/09/17



[8]ページ先頭

©2009-2025 Movatter.jp