pandemia.messagebus¶
Simple synchronous messagebus implementation.
Module Contents¶
Classes¶
Message broker. |
Attributes¶
- pandemia.messagebus.log¶
- class pandemia.messagebus.MessageBus¶
Message broker.
Objects subscribe to this bus by providing a callback function that is invoked whenever a message is published. Multiple callbacks may be registered for a single topic, in which case they are invoked in-order.
Callbacks may return a value, MessageBus.CONSUME, which stops propagation of the event.
Topics do not need creating explicitly.
- CONSUME = True¶
- pub¶
- sub¶
- subscribe(topic: str, callback: Callable, owner: Any) None¶
Subscribe to a topic, providing a callback function that will be invoked when an event is published on that topic.
- Parameters:
topic (str) – The topic to respond to
callback (callable) – The function to invoke when an event is called
owner (object) – The object ‘owning’ this subscription. Used to unsubscribe.
- publish(topic: str, *args, **kwargs) None¶
Publish an event to the messagebus on the topic given.
All handlers will be called in the order they subscribed.
- Parameters:
topic (str) – The topic to publish on
*args – Positional arguments to the callback
**kwargs – Keyword arguments to the callback