# Publish/Subscribe

MQTT is based on a publish/subscribe model for message communication. The client can be both a publisher (publish a message) and a subscriber (subscribe to a topic). That is, when a client publishes a message to the broker, the broker will forward the message to clients subscribed to this topic after receiving it.

This chapter will introduce the commonly used MQTT client tools, and will walk you through the process of establishing client connections, subscribing to topics, publishing messages, as well as receiving and viewing messages.

Messaging workflow

Below is the typical workflow on how a message is published and then received by the subscriber.

  1. Publishers and subscribers initiate the connection request to EMQX with the correct connection URL and authentication information. Note: Both are connected to the same EMQX;
  2. The subscriber subscribes to the topic. By default, messages with no matching subscribers will be discarded immediately;
  3. The publisher publishes messages, please ensure that the topic of the message can be matched with the subscriber, and the subscriber has subscribed to the corresponding topic;
  4. The subscriber receives the message.

In the next section, we will introduce how to test the connection with different client tools, including Dashboard Websocket and MQTT X.