Message Bus¶
Source code: event_collector.messagebus.py
This module implements a message bus used internally between the CollectorQueue and other components.
The MessageBus allows one component of the event-collector system to listen to messages or bus events emitted by other components without explicit tight coupling.
MessageBus classes¶
- class event_collector.messagebus.Message¶
Messageis a generic base class for a bus message.
- class event_collector.messagebus.Command¶
Commandis a generic base class for a bus command.
- class event_collector.messagebus.MessageBus(msg_handlers: dict[type[T_Message], list[Callable[[T_Message, deque[BusEvent]], Awaitable[None]]]] | None = None, cmd_handlers: dict[type[T_Command], Callable[[T_Command, deque[BusEvent]], Awaitable[None]]] | None = None)¶
The message bus works by dispatching messages or commands to handlers.
A
MessageBusinstance is initialized with a set ofMsgHandlersandCmdHandlers.Components define subclasses of
MessageorCommandand dispatch or publish these events through the message bus. For each message or command, the message bus will check if any message or command handlers are registered to listen to the events. If a handler is registered, the bus will call the handler function when the message or command is triggered by the “dispatch” method.The
CollectorQueueemits a set ofMessagesthat your application can listen to. These are documented in the (queue) module.