0
0
IOT Protocolsdevops~6 mins

Publish-subscribe architecture in IOT Protocols - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine trying to share news with many friends without calling each one individually. The publish-subscribe architecture solves this by letting senders and receivers communicate through a middleman, making message sharing easier and more flexible.
Explanation
Publishers
Publishers are the sources that create and send messages. They do not need to know who will receive the messages or how many will get them. Their job is simply to publish information to a common channel.
Publishers send messages without needing to know the receivers.
Subscribers
Subscribers express interest in certain types of messages by subscribing to specific topics. They receive only the messages that match their interests, without knowing who sent them. This allows them to get relevant updates easily.
Subscribers receive messages based on their chosen topics.
Broker
The broker acts as a middleman between publishers and subscribers. It receives messages from publishers and forwards them to the right subscribers based on the topics. This central role simplifies communication and manages message delivery.
The broker routes messages from publishers to the correct subscribers.
Topics
Topics are named channels or categories that organize messages. Publishers send messages to topics, and subscribers listen to topics they care about. This system keeps messages organized and targeted.
Topics organize messages so subscribers get only what they want.
Real World Analogy

Think of a magazine publisher who prints different magazines on various subjects. Readers subscribe to the magazines they like, and the publisher sends each magazine only to those readers. The post office acts like the broker, delivering the right magazines to the right subscribers.

Publishers → Magazine publisher printing magazines
Subscribers → Readers subscribing to specific magazines
Broker → Post office delivering magazines to readers
Topics → Different magazine subjects or categories
Diagram
Diagram
┌────────────┐       ┌─────────┐       ┌─────────────┐
│ Publisher 1│──────▶│         │       │ Subscriber 1│
└────────────┘       │         │       └─────────────┘
                     │ Broker  │──────▶
┌────────────┐       │         │       ┌─────────────┐
│ Publisher 2│──────▶│         │       │ Subscriber 2│
└────────────┘       └─────────┘       └─────────────┘

Topics: Weather, News, Sports
This diagram shows publishers sending messages to a broker, which then forwards them to subscribers based on topics.
Key Facts
PublisherA component that sends messages to a topic without knowing the receivers.
SubscriberA component that receives messages by subscribing to specific topics.
BrokerA server that routes messages from publishers to subscribers based on topics.
TopicA named channel that organizes messages for selective delivery.
DecouplingPublish-subscribe architecture separates senders and receivers so they do not depend on each other.
Common Confusions
Publishers must know who the subscribers are.
Publishers must know who the subscribers are. Publishers send messages to topics without knowing or managing subscribers; the broker handles delivery.
Subscribers receive all messages from all publishers.
Subscribers receive all messages from all publishers. Subscribers only receive messages from topics they subscribe to, not all messages.
The broker stores messages permanently.
The broker stores messages permanently. Most brokers forward messages immediately and do not store them permanently unless configured for persistence.
Summary
Publish-subscribe architecture uses a broker to connect message senders (publishers) and receivers (subscribers) without direct links.
Messages are organized by topics, allowing subscribers to receive only what interests them.
This design simplifies communication and supports flexible, scalable message distribution.