Reference
shared.messaging.broker ¶
AsyncMessageContext ¶
Broker ¶
Bases: ABC
Base class for the brokers. The broker's responsibility is to receive messages and transmit them to the subscribers.
This class makes no assumption regarding serialization or transport layer.
publish
abstractmethod
¶
subscribe
abstractmethod
¶
Subscribe to a message type with a handler function. The predicate is used to add a subscription filter depending on the message content
Source code in shared/messaging/broker.py
subscribe_async
abstractmethod
¶
Subscribe to a message type with a handler function and a queue name. The predicate is used to add a subscription filter depending on the message content
Source code in shared/messaging/broker.py
MemoryBroker ¶
Bases: Broker
A broker that stores the subscribers in memory and calls them synchronously or asynchronously.
It's the responsibility of the handlers to manage exceptions, the broker only guarantees delivery to all subscribers.
Source code in shared/messaging/broker.py
publish ¶
Source code in shared/messaging/broker.py
subscribe ¶
Source code in shared/messaging/broker.py
subscribe_async ¶
Source code in shared/messaging/broker.py
NullBroker ¶
TestBroker ¶
Bases: Broker
Test broker that can trigger handlers manually.
Source code in shared/messaging/broker.py
process_messages ¶
Source code in shared/messaging/broker.py
publish ¶
subscribe ¶
Source code in shared/messaging/broker.py
subscribe_async ¶
Source code in shared/messaging/broker.py
get_message_broker ¶
Return the process-local broker. Raises if not initialized to fail fast in prod.
Source code in shared/messaging/broker.py
get_unique_name_for_message ¶
override_message_broker ¶
Temporarily replace the process-local broker for the duration of the context. Restores the previous broker afterwards. Does not close either instance.
Source code in shared/messaging/broker.py
shared.messaging.consumer ¶
Consumer ¶
Bases: Generic[T]
Generic consumer for a given message type.
This implementation requires to pass the type as parameter because there is no supported API for getting the type from the generic information. See https://stackoverflow.com/questions/57706180/generict-base-class-how-to-get-type-of-t-from-within-instance ⧉
Source code in shared/messaging/consumer.py
on_message ¶
Source code in shared/messaging/consumer.py
shared.messaging.exceptions ¶
ConsumerAlreadyRegisteredError ¶
Bases: PubSubError
Raised when a consumer's on_message is used more than once.
PubSubError ¶
Bases: Exception
Base class for all pubsub exceptions.
shared.messaging.message ¶
Message
dataclass
¶
Serializable and hashable base class for all messages.