The Pub/Sub API¶
Topicis like a channel to distribute information (events), in a Pub/Sub environment.
On one side is a
Publisherthat provides ‘data’ (value’s, events, …).
The other side has
Subscriberswho subscribe to the topic (with callbacks).
Subscriberare abstract types; there is no concrete class (needed).
Any module that calls
publish()is called a
Publisher; likewise, a
Subscriberis anyone calling
Commonly there is only one
Publisher(for a given Topic); that is not mandatory, however.
This method is called by the
Publisher, whenever a new value is to be shared. When force is False (default), the
valuewill only be distributed when it differs from the previous value. To force distribution, set force to True.
This method is called by all
Subscribersto register a callback, which is called on new ‘data’.
def callback([self,] value, topic):
Where value is the ‘data’ passed to
publish()and ‘topic’ is the
Topicinstance, use to route it.
When the callback is a method, the self parameter is automagically remembered by Python. For function-callbacks, leave it out.
Publisher and the
Subscribers are Abstract Types.
Any code that will call
pubsub.Topic.publish(). It can be a class, a module or just code …