Chapters

MQTT Publish-Subscribe: Reference

I’m Bex. These reference excerpts support MQTT Publish-Subscribe Basics. Return there to follow the boiler-sensor house. The old check headings in the preserved excerpts refer to the standalone knowledge check.

Route model and simulation

I’ll start with the route model behind the chapter’s matching example.

A topic filter asks which messages a client wants. An access-control list, or ACL, says which topics that identity may read or write. A match and a permission answer different questions. Keep both in the route record.

For the boiler prediction, assume the subscriptions have been accepted, both listeners are connected and authorized, and transfer succeeds. The operations screen asks for plant/+/temperature. The alarm service asks for plant/#. Read plus as “one level” and hash as “the rest of this branch”. Hash must be the final filter level.

Copy the concrete publication beside each filter. Compare literal levels first, then let each wildcard consume only its allowed levels. Predict the matching set. To test the prediction, request the broker’s forwarding trace and a subscriber receipt with the topic and payload. Broker acceptance alone stops too early.

Simulation · interactive

Publish/Subscribe Flow Workbench

Explore how the system behaves.

The MQTT Roles

Publisher

Sends the boiler reading to plant/boiler7/temperature. It names the route, not each receiving application.

Broker

Compares that name with stored filters and forwards permitted matches. Authentication and topic permissions need explicit configuration.

Subscriber

Requests a filter such as plant/+/temperature. It checks the content and age of the readings it receives.

Beginner Examples

Worked example. The input is plant/boiler7/temperature with payload 83.4 C, or 83.4 degrees Celsius. For the operations filter, plant agrees, plus consumes boiler7, and temperature agrees: match. For the alarm filter, plant agrees and hash consumes the remaining branch: match. The exact filter plant/boiler7/pressure fails at the last level: no match. Under our delivery assumptions, the operations screen and alarm service receive the reading. The pressure monitor does not.

Overview Knowledge Check

For the next reading, compare the topic with each filter, check permission, then check receipt. Adding a listener changes the broker’s subscriptions, not the boiler sensor’s destination list.

Topic record and design workflow

With that route in mind, I’ll keep the original design record here for a closer review.

Quality of service, shortened to QoS, is the MQTT delivery level. A retained message is a last-known snapshot stored for a topic. A session holds client-related state such as subscriptions and eligible queued messages. A configured last will lets the broker publish status after an unexpected connection loss. A duplicate repeats a message; a stale value is too old for its intended use. These choices belong in the record because matching alone does not settle them.

Topic Record Workflow

1. Name the message family. State whether the message is telemetry, state, command, alert, configuration, or maintenance data.
2. Write the topic shape. Choose stable path levels such as site, area, device, capability, and signal. Keep names predictable and avoid hiding meaning in payload-only fields.
3. Define subscription filters. Record exact topics and any + or # wildcard use, including who owns each broad subscription.
4. Choose delivery state. Record QoS, retained-message use, session behavior, last-will status, duplicate handling, and stale-data policy.
5. Keep broker evidence. Record client id, authentication result, publish count, matched subscriptions, broker forwarding and subscriber-receipt evidence, including protocol acknowledgements when the QoS provides them, disconnects, and rejected topics.

Worked Example: Greenhouse Telemetry

The greenhouse sensor publishes to site/greenhouse-2/sensor-17/air/temperature. Compare it with site/greenhouse-2/+/air/temperature. Site and greenhouse agree; plus takes the sensor level; air and temperature agree. The dashboard can cover other sensors at the same greenhouse without receiving other signal types. The alarm rule and history archive still need their own subscription and application requirements.

Design Item
Record
Why It Matters
Review Evidence
Publish topic
site/greenhouse-2/sensor-17/air/temperature
The path names the site, device, capability, and measured signal.
Request an accepted-publish trace tied to the expected client identity.
Dashboard subscription
site/greenhouse-2/+/air/temperature
The plus wildcard matches one sensor level; site and signal remain fixed.
Compare expected matching topics with the dashboard’s actual receipt trace.
Operations subscription
site/greenhouse-2/#
A broad filter is reserved for operations tools, not embedded in every application.
Test that an ordinary dashboard identity cannot receive the operations-only branches.
Freshness policy
Timestamp in payload, stale marker in dashboard, and last-will status topic.
A last-known value can still be old. Freshness must be visible to the reader.
Test that retained or delayed old values appear stale rather than live.

Correct topic, delivery, and freshness mistakes.

  1. Topic: Do not use site/# for a dashboard that needs only greenhouse 2 temperature readings. Publish to site/greenhouse-2/sensor-17/air/temperature, whose path names site, device, capability, and signal; subscribe with site/greenhouse-2/+/air/temperature to cover its matching sensors without other sites or signal types.
  2. QoS: Do not treat a matching topic as a delivery-state record. Record QoS, retained use, session behavior, and last will separately so the delivery assumptions can be reviewed.
  3. Subscriber: Do not display retained or delayed values as live without checking their age. Keep the broad # filter for operations alone, and mark old values as stale in the dashboard.

This record avoids two common mistakes: making the topic too vague for authorization, and using wildcards so broadly that subscribers receive data they do not need or should not see.

Practitioner Knowledge Check

Apply the same rule to the humidity recheck: hold greenhouse 4 and humidity fixed, then allow the sensor level to vary. A smaller filter does not replace an ACL; it makes the intended audience easier to state and test.

Broker boundaries and delivery reference

From the topic record, I’ll turn to the evidence kept at each broker boundary.

Separate authentication, which checks identity, from authorization, which checks permission. A staff display may be allowed to read room temperatures while command topics remain denied. Keep evidence of the allowed path and the denied path.

Broker Boundary Ledger

Boundary
Broker Responsibility
Evidence to Keep
Failure Question
Client connection
Accept or reject the client identity and connection parameters.
Client id, authentication result, connection time, clean or persistent session setting.
Did the expected client connect, and what session policy was accepted?
Publish authorization
Decide whether a client may publish to a topic.
Accepted and rejected publish logs, ACL rule, topic path, payload size, QoS.
Did a device publish only to its permitted namespace?
Subscription matching
Match exact topics and wildcard filters to incoming publishes.
Subscription filter, matched topic count, broad wildcard ownership, subscriber identity.
Does this concrete topic match the intended filter, and is that subscriber authorized?
Delivery state
Apply QoS behavior, retained-message handling, queued messages, and last-will publication.
Applicable QoS acknowledgements, retained state, session queue, duplicate handling, last-will event.
Can the system explain duplicates, stale state, offline status, and missed messages?

Mechanics That Matter

Topic filters select routes. Plus matches one level. A final hash includes the remaining branch. Neither checks payload meaning. QoS controls delivery. Quality of service is the MQTT delivery level. QoS zero has no protocol acknowledgement; higher levels still do not prove application action. Applications still need freshness and duplicate handling. An idempotent operation keeps the same intended state when repeated. Retained state belongs to a topic. A new matching subscription can receive its last-known snapshot. Session state belongs to a client. Its settings and broker limits decide which eligible messages can wait while that client is offline. A retained snapshot and an offline queue answer different questions.

Topic board

  1. Topic: Do not use the payload value to decide routing. Compare the concrete topic name with the filter before inspecting the value.
  2. QoS: Do not extend a delivery confirmation to a physical result. Ask what this delivery leg confirms.
  3. Subscriber: Do not assume that a late value is fresh. Check whether it came from retained topic state or a client queue, then check its age.

Common Review Pitfalls

Using hash for every application admits unrelated branches. Narrow the filter and enforce its permissions at the broker. Checking authorization only in the screen lets unwanted data reach that client before it hides it. Deny the route at the broker. Treating retained as fresh makes an old snapshot look live. Show its timestamp or age. Treating silence as health hides missing devices. Configure status, a Will, and a stale-data rule; a Will reports an unexpected connection loss, not a temperature or a complete fault diagnosis.

Under-the-Hood Knowledge Check

Keep the first missing piece of evidence in the record. A failed match calls for a topic or filter correction. An authorization failure calls for a permission review. A received but stale reading calls for the application’s freshness rule. Increasing QoS cannot repair all three.

Detail notes moved from the chapter

Technical detail

One route, two listeners

Name the sender, routing service, and receiving applications.

Open as a page

Technical detail

One route, two listeners

The sensor sends to the broker rather than addressing the operations screen or alarm service directly. The broker compares a publication’s topic with those filters and forwards permitted matches.

Technical detail

Command and physical result

Keep receipt evidence beside reported state.

Open as a page

Technical detail

Command and physical result

Receiving a message and carrying out its request are separate events. A broker’s acceptance cannot show that a physical valve moved. Likewise, a screen displaying a temperature does not establish that the sensor measured the boiler correctly. Keep the route, the receipt, and the physical result separate when explaining what happened.

Hi, I’m Broker Bex. What do you need?

Find help

Let’s find what you need

Find a lesson or return to your module guide.

Give feedback

Help improve this chapter

Tell us what helped or what needs fixing.

Tips

Try a small next step

A few ways to get more from this chapter.

Ask AI

Continue the conversation

Take the conversation further with your preferred assistant.

AI help is available in supported modules when enabled in Settings.

No live person answers on independent study. Feedback does not promise a personal reply.

For welfare or safety concerns, follow your school’s procedures outside IoTClass.