liveBook · Manning

Publish/subscribe model

As explained in Software Design for Python Programmers

The publisher-subscriber model is a communication pattern in which a publisher produces state or event information and subscribers receive notifications about it.

The publish/subscribe model separates a publisher that produces state or event information from subscribers that process notifications independently. The publisher does not know how subscribers are implemented or what they do with the content. section 12.0 section 12.2

Baseball game reports

A baseball reporter publishes each hit or out as it occurs. A logger records events immediately, while table and graph generators accumulate information and report after the game. Each subscriber handles the same events differently. section 12.1

A flexible design lets the system:

  • Create content at arbitrary times and notify every current subscriber immediately. section 12.1.1
  • Let subscribers fetch content selectively and process it however they choose. section 12.1.1
  • Add or remove subscribers without changing the publisher’s code. section 12.1.1 section 12.2

How Software Design for Python Programmers covers it

How deep it goes
Defines notification, fetching, independence, and subscription changes, but does not show implementation code.
Examples
Uses online news notifications and baseball hit events feeding logger, table, and graph reports.
What it assumes
Teaches publisher, subscriber, subject, observer, producer, and consumer terminology through news and sports examples.
What you can do after
Evaluate designs for loose coupling, selective content retrieval, and subscriber changes without publisher modifications.
How it connects
Connects the publisher to the Observer Design Pattern, subject and observer objects, and the producer–consumer model.

Also explained in

Compare how 5 books explain publish/subscribe model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Design for Python Programmers. The section links point to the parts of the book it draws on.