bg_image
header

Publish-Subscribe-Pattern - PubSub

The Publish/Subscribe pattern (often abbreviated as Pub/Sub) is a communication pattern in software development that enables loose coupling between components or systems. It involves two main actors: the Publisher and the Subscriber.

  • Publisher: Responsible for generating and publishing messages or events. A Publisher sends messages to a central location, the Message Broker or Pub/Sub system.

  • Subscriber: Registers for specific types of messages or topics it wants to react to. A Subscriber receives messages published by the Publisher and forwarded by the Message Broker to the respective subscribers.

The key concept in the Pub/Sub pattern is that the Publisher doesn't send messages directly to specific recipients but rather to a central intermediary system. This system stores messages and then distributes them to all Subscribers interested in the corresponding topic or type of message.

The pattern enables decoupled, scalable, and flexible communication between different parts of an application or between different applications. It's used in various systems and technologies, including messaging brokers, cloud platforms, IoT (Internet of Things), real-time analytics, and other scenarios requiring flexible message delivery.

 


Subscriber

A Subscriber, in the context of a message broker or messaging system, is an entity or component that receives messages and acts upon them. While the Publisher generates messages and sends them to the message broker, the Subscriber is a part of the system that has subscribed to receive specific types of messages forwarded by the message broker.

Subscribers are recipients of messages who subscribe to particular channels, topics, or types of messages that are relevant to them. Once the message broker receives messages that match the subscription criteria of the Subscribers, it forwards those messages to the corresponding Subscribers, who can then process or respond to them.

For instance, in a messaging system, a Subscriber could be an application waiting for specific types of notifications. Once the message broker receives messages that meet those criteria, it forwards them to the respective application, which then processes or reacts to the received information.

 


Publisher

In the context of a message broker, a "Publisher" refers to a component or entity that generates messages and sends them to the message broker. A message broker serves as an intermediary or middleware that facilitates communication between different applications or systems by receiving, processing, and forwarding messages to the appropriate recipients.

The Publisher is the source of messages within this system. It produces messages and sends them to the message broker, which then forwards them to other systems or subscribers. Essentially, the Publisher sends information or events that can be received and processed by other parts of the system or by subscribers.

For example, in a messaging system, a Publisher could be an IoT device generating sensor data and sending it to the message broker, which then disseminates this data to various subscribers or receivers that process or act upon this information.