Test MQTT TLS and reliability
Use a TLS WebSocket MQTT connection to inspect QoS, retained state, last will and reconnect boundaries.

Broker Bex: I want you to follow each acknowledgement and state transition before naming a reliability guarantee.
Predict the reading, then compare it with the measurement.
Python 3 in your browser (JupyterLite)
Python · no installUse a TLS WebSocket MQTT connection to inspect QoS, retained state, last will and reconnect boundaries.
Open the notebook in your browser and run each Python cell; no install or account is needed.
Three ways to run: use JupyterLite here with no install; run main.py locally from the downloadable lab folder; or open the same notebook in Google Colab.
Steps
Step 1
- Do
- Connect over the notebook's wss endpoint and identify the trust boundary.
- You will see
- The step names the deployed WSS URL and explains that TLS does not authorize topic meaning.
- Why it matters
- Transport protection is necessary but separate from identity, ACL and application checks.

Step 1 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab) Step 2
- Do
- Publish one message at each MQTT QoS level.
- You will see
- The trace shows QoS 0, 1 and 2 callback delivery and their handshakes.
- Why it matters
- QoS changes MQTT transfer behavior, not exactly-once database effects.

Step 2 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab) Step 3
- Do
- Publish retained state and join with a late subscriber.
- You will see
- The late subscriber receives online with the retained flag before cleanup.
- Why it matters
- Retained state is a current snapshot, not an event history.

Step 3 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab) Step 4
- Do
- Close a client without DISCONNECT to trigger its last will.
- You will see
- The watcher receives the offline will while a graceful close is explicitly contrasted.
- Why it matters
- A will reports an ungraceful session end but cannot diagnose its cause.

Step 4 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab) Step 5
- Do
- Reconnect a durable client after an offline QoS 1 publish.
- You will see
- The reused client identity receives the queued payload after reconnect.
- Why it matters
- Session persistence requires broker support, a stable identity and non-clean session state.

Step 5 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab) Step 6
- Do
- State the processing guarantee for every QoS level.
- You will see
- The trace separates MQTT exchange guarantees from idempotent application actions.
- Why it matters
- A duplicate transport delivery must not create a duplicate physical effect.

Step 6 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab) Step 7
- Do
- Clean retained state and close the bounded public-broker test.
- You will see
- The final record confirms cleanup, disconnects and the production-scope warning.
- Why it matters
- A shared public broker is suitable only for fictional learning traffic.

Step 7 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab)
Chapter checks
These questions refer to the chapter’s examples. Use the return links to review their answers.
A temperature sensor in a smart building should only be able to publish its own readings. Which ACL rule best enforces this least-privilege requirement?
Return to the chapter’s knowledge checkYour company deploys MQTT sensors in customer buildings. A sensor is configured with client_id='sensor' and username='device' with a shared password. What's the main security risk?
Return to the chapter’s knowledge check