Pubsub
shared.pubsub.topics ¶
Topic ¶
Bases: Generic[T]
Generic T message distribution following the publish/subscribe pattern
This class is a simple device to decouple the publisher from the subscribers. It doesn't implement anything beyond simple message distribution to a list of subscribers. In particular there is no async job processing or exception handling whatsoever.
The contract is as follows:
- Publishers call the topic publish method to send a message to all subscribers by
calling their receive method
- Subscribers call the subscribe method to register themselves as subscribers of a topic,
and the unsubscribe method to unregister themselves
- Registration can be static or dynamic
- Publication is synchronous and blocking on the publisher side
- Messages are distributed to all subscribers in no particular order
- Subscribers' receive method must not perform any blocking or costly operation
and must not raise any exception; they should be as fast as possible
- Subscribers are free to implement their own exception handling and async job processing
as long as they respect the contract above