This flow shows how a publisher sends a message to a broker, which then forwards it to all subscribers of the topic.
Execution Sample
IOT Protocols
Publisher -> Broker: Publish 'temp/room1' = 22°C
Broker -> Subscribers: Forward 'temp/room1' = 22°C
Subscriber: Receive and process message
A publisher sends a temperature message to the broker, which forwards it to all subscribers of 'temp/room1'.
Process Table
Step
Action
Topic
Message
Broker State
Subscribers Notified
1
Publisher sends message
temp/room1
22°C
Message received
None yet
2
Broker checks topic
temp/room1
22°C
Topic found with 2 subscribers
None yet
3
Broker forwards message
temp/room1
22°C
Message forwarded to subscribers
Subscriber A, Subscriber B
4
Subscribers receive message
temp/room1
22°C
No change
Subscriber A processes, Subscriber B processes
5
Subscribers process message
temp/room1
22°C
No change
Processing complete
💡 Message delivered to all subscribers; process complete.
Status Tracker
Variable
Start
After Step 1
After Step 2
After Step 3
After Step 4
Final
Message
None
22°C
22°C
22°C
22°C
22°C
Broker Queue
Empty
22°C received
Checked topic
Forwarded message
Empty
Empty
Subscribers Notified
None
None
None
Subscriber A, Subscriber B
Received message
Processed message
Key Moments - 3 Insights
Why does the broker need to check the topic before forwarding?
The broker checks the topic to know which subscribers are interested. Without this, it wouldn't know where to send the message. See execution_table step 2.
Do subscribers get the message directly from the publisher?
No, subscribers get messages only from the broker, not directly from the publisher. The broker manages message delivery. See execution_table steps 1 and 3.
What happens if no subscribers exist for a topic?
The broker receives the message but finds no subscribers to forward to, so the message is discarded or stored depending on configuration. This is implied in step 2 if subscriber count is zero.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does the broker forward the message to subscribers?
AStep 2
BStep 3
CStep 4
DStep 1
💡 Hint
Check the 'Action' and 'Subscribers Notified' columns in execution_table row for step 3.
According to variable_tracker, what is the state of the broker queue after step 3?
AEmpty
BChecked topic
CForwarded message
D22°C received
💡 Hint
Look at the 'Broker Queue' row and the column 'After Step 3' in variable_tracker.
If a new subscriber joins after step 3, how would the broker's behavior change?
ABroker ignores new subscriber for past messages
BBroker deletes all messages
CBroker forwards message to the new subscriber immediately
DBroker sends message back to publisher
💡 Hint
Consider that messages are forwarded only to subscribers registered at the time of forwarding (see execution_table step 3).
Concept Snapshot
Publish-subscribe architecture:
- Publishers send messages to a broker on topics.
- Broker forwards messages to all subscribers of those topics.
- Subscribers receive messages only from the broker.
- Decouples senders and receivers for flexible communication.
- Broker manages message routing and delivery.
Full Transcript
In publish-subscribe architecture, a publisher sends a message to a broker on a specific topic. The broker receives the message and checks which subscribers are registered for that topic. Then, the broker forwards the message to all those subscribers. Subscribers receive and process the message. This system allows many publishers and subscribers to communicate without knowing each other directly. The broker acts as a middleman managing message delivery based on topics.