Router¶
Source code: event_collector.base.router.py
This module contains definition for the base router class and the simple router.
A Router is used to dispatch an event payload to collectors. The default router is
SimpleRouterand is used by the collector queue to handle events if no custom router is supplied at initialization.
- class event_collector.router.Router(collectors: CollectorDict | None = None)¶
This is the abstract base class for a router.
- collectors: CollectorDict¶
The router should be initialized with a dict of Collector instances (with Collector
keyas the dict key and the Collector instance as the dict value). The collector dict will be used to handle event routing by thehandle_eventmethod.
- abstractmethod async handle_event(payload: Payload) ResultList¶
The
handle_eventmethod should implement logic to dispatch an event payload to one or more collectors. The return value must be aResultList.
- class event_collector.router.SimpleRouter(collectors: CollectorDict | None = None)¶
The
SimpleRouteris the default router used by the collector queue to handle payload dispatching. This router handles the 3 delivery modes implemented by the collector queue: direct key, topics, and broadcast. Thehandle_eventensures that all event payloads sent to the collectors return validResultobject(s).- collectors: CollectorDict¶
As with the base
Router,collectorsshould be a dict of Collector instances (CollectorDict).
- async handle_event(payload: Payload) ResultList¶
Handle incoming event payload by sending payload to collectors using the payload’s delivery mode.
This method will return a ResultList, because, depending on the delivery mode, the event payload will be sent to one or more collectors. So it’s valid to have multiple return values.