How Does MQTT Route Messages Through a Broker?
- Basic
- Article
- Ages 15+
- 4 min read

Contents
- Publisher
- Broker
- Subscribers
What you will learn
- Describe the roles of publisher, broker and subscriber.
- Understand what topics and wildcards are for.
- Tell the three Quality of Service levels apart.
Before you start
It helps to know how IoT devices connect to a network.
How does a broker pass messages on?
MQTT is a Client Server publish/subscribe messaging transport protocol. The Server is a program or device that acts as an intermediary between Clients which publish messages and Clients which have made Subscriptions.
The broker routes messages to the appropriate subscribers based on the topic hierarchy. MQTT is light weight, open, simple and designed to be easy to implement.
- Publisher
- Message with a topic
- Broker
- Subscriber to the topic
- Party not subscribed
How do topics and wildcards work?
A topic name is the label attached to a message, matched against the subscriptions the server knows. A topic filter is an expression in a subscription that shows interest in one or more topics.
The forward slash separates topic levels. The + wildcard matches exactly one level and must occupy a whole level in a filter. The # wildcard matches the parent level and any number of child levels; it must appear alone or after a /, and be the final character in a filter.
- Root of the topic tree
- One topic level
- The + wildcard gathers topics at one level
How do the three Quality of Service levels differ?
MQTT has three Quality of Service levels: QoS 0 (at most once) uses best effort; QoS 1 (at least once) assures delivery but may produce duplicates; QoS 2 (exactly once) assures one delivery. These levels describe each delivery hop from one sender to one receiver; the broker treats each recipient independently.
- At most once: send only
- At least once: with confirmation
- Exactly once: multi-step confirmation
MQTT also decouples by time, allowing the broker to store messages for clients that are not online, while the session and subscription remain valid. Storage also depends on message QoS, message expiry and broker policy. If a client configured a Will Message, the server can publish it after an abnormal connection closure; timing also depends on Will Delay and the session.
Real-world example
With an adult, think of a temperature sensor at home. The sensor publishes a reading to a topic. A phone and a screen in the house both subscribe to that topic, so both receive the reading.
Common misunderstandings
Devices must connect straight to each other. With publish/subscribe, applications are decoupled and go through the broker.
Every message arrives exactly once. That is only one of three levels; at least once can produce duplicates.
Frequently asked questions
What is MQTT?
MQTT is a light, simple publish/subscribe messaging transport protocol.
What does a broker do?
The broker routes messages to the appropriate subscribers based on the topic hierarchy.
What are wildcards for?
The + wildcard matches exactly one topic level and must occupy that whole level in a filter; # matches the parent level and any number of child levels, must appear alone or after a /, and must be the final character in a filter.
What is a will message?
A message configured by a client for the server to potentially publish after an abnormal closure, depending on the delay and session state.
Summary
Terms in this article
English and Vietnamese terms, with the meanings used here. Hover, tap or Tab to a term with a dotted underline for an explanation as you read.
- MQTT
- A lightweight protocol that moves messages by publish and subscribe between clients and a server.
- Broker
- The intermediary server that receives messages and passes them to matching subscribers.
- TopicChủ đề
- A label attached to a message; / separates a topic name into levels.
- WildcardKý tự thay thế
- A character in a topic filter: + matches one whole level; # matches the parent and child levels and appears at the end of the filter.
- Quality of ServiceChất lượng dịch vụ
- The delivery guarantee level: at most once, at least once or exactly once.
- Will messageBản tin di chúc
- A message configured by a client for the server to potentially publish after abnormal closure, depending on delay and session state.
This article is not marked as viewed
Spotted something wrong or unsafe?
Tell the administrator by email. The message already has the article title and address.
You may also like
BasicHow Does Arduino Run setup and loop?
An Arduino sketch has two functions: setup runs once and loop repeats forever. See the run order, why loop never pauses and what delay does.
Internet of Things (IoT)4 min read
BasicHow Does an ESP32 Board Run and Communicate?
An ESP32 board pairs an ESP32 module with a USB port and pin headers. See its parts, how firmware is loaded over serial, and its Wi-Fi and Bluetooth.
Internet of Things (IoT)4 min read
StarterOverview of ESP32, Arduino and Other Boards
An overview of ESP32 and Arduino boards and how to choose by connectivity, voltage, power and microcontroller.
Internet of Things (IoT)4 min read
BasicHow Does Modbus RTU Exchange Data?
Modbus RTU works by request and response between a master and slaves. See addresses, function codes, error checks and how frames are split by silent gaps.
Internet of Things (IoT)4 min read
Sources
These sources are written for older readers. If they feel hard, read them with an adult.
- MQTT Version 5.0(opens in a new tab)
OASISTier C: other sourcesRead on October 29, 2026
- MQTT Publish / Subscribe Architecture (MQTT Essentials Part 2)(opens in a new tab)
HiveMQTier C: other sourcesRead on October 29, 2026
