liveBook · Manning

Publish-subscribe pattern

As explained in Robotics for Programmers

Publish-subscribe is a communication pattern in which publishers send messages to named channels and subscribers receive them without direct coupling.

Publish/subscribe (pub-sub) is a messaging pattern for distributed robot software. A publisher sends messages to a named topic; subscribers receive messages from that topic. Publishers and subscribers do not need to know each other or where either runs. Middleware delivers messages, so a component can move between computers without changing its communication partner. section 4.2 section 4.8

A topic is a named logical channel with a particular message type. Components connect by agreeing on the topic name and message type, not by directly calling one another. A topic can have multiple publishers and multiple subscribers, while each node may publish and subscribe to any number of topics. section 4.2 section 4.4

Figure 4.4 The publish-subscribe (pub-sub) communication pattern uses named logical channels called topics. These topics allow decoupled publishers and subscribers to exchange specific message types without knowing each other’s network locations. In general, each topic can have multiple publishers and multiple subscribers, and each topic can have a specific message type.
CH04 Fxx bihlmaier pub sub

The topic sits between senders and receivers: middleware routes typed messages through the named channel rather than exposing network locations. section 4.2

In a robot sensing-to-planning loop, pub-sub separates responsibilities:

  • An image-processing component detects objects, packages them in an ObjectList message, and publishes them on detected_objects. section 4.2
  • A planning component subscribes to detected_objects and runs its callback whenever an ObjectList message arrives. section 4.2
  • The components can be deployed together or on different computers while retaining the same topic-based connection. section 4.2

In ROS, nodes communicate through topics as well as services, actions, and parameters. ROS topics implement pub-sub: nodes contain publishers and subscribers, and the ROS graph is formed by the nodes and their topic connections. ROS message types are defined in .msg files and become language-specific data structures through the build tools. section 4.4

A minimal ROS topic pair

A Python publisher node creates a publisher for String messages on my_topic, then a timer publishes a timestamped “Hello World” message. A subscriber node creates a matching String subscription on my_topic; its callback logs each received message. The shared topic name and type let middleware connect the independent nodes. section 4.4 section 4.4

Pub-sub provides deployment flexibility, not a guarantee that distributed communication is simple. Networked robot components still depend on middleware and must account for the realities of distributed systems. For communication requiring real-time mechanisms, fieldbus protocols and industrial networks are identified separately. section 4.8

How Robotics for Programmers covers it

How deep it goes
Defines topics, publishers, subscribers, message types, callbacks, and ROS node connections through working Python examples.
Examples
Uses detected-object messages from image processing to planning and paired ROS String publisher/subscriber nodes.
What it assumes
Introduces topic communication from zero while using Python-like code and ROS nodes as the implementation setting.
What you can do after
Apply it via rclpy by creating typed publishers and subscriptions connected through shared topic names.
How it connects
Connects middleware, distributed systems, ROS nodes, ROS graph, message types, services, actions, and parameters.

Also explained in

Compare how 8 books explain publish-subscribe pattern →

Related concepts

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