evoq_event_router (evoq v1.30.1)

View Source

Routes events to handlers by event type.

Receives events from reckon-db subscriptions and routes them to interested handlers based on event type.

Key features: - Per-event-type routing (not per-stream) - Event upcasting before delivery - Delivery isolated per handler (see below) - Telemetry for observability

Delivery isolation

Each local handler process gets its own courier: a process that hands it its events with evoq_event_handler:notify/4, one at a time, in the order the router routed them. The router only passes an event to the courier, so a handler that is slow, blocked, or sleeping out a {retry, DelayMs} backoff delays its own events and nobody else's. Before, the router made that call itself, handler after handler, and one slow handler held up every handler and projection on the node (evoq#30). The handler still acknowledges its own write to a strong-consistency waiter. A courier ends when its handler does.

Summary

Functions

The type this event is delivered as, and the handler processes that delivery reaches.

Route an event to interested handlers.

Route an event with options.

Route multiple events to interested handlers.

Start the event router.

Functions

delivery_targets(Event)

-spec delivery_targets(map()) -> {binary(), [pid()]}.

The type this event is delivered as, and the handler processes that delivery reaches.

Read from the registry, through the same upcasting the delivery does, so a caller asking "who will see this event" gets the answer the router acts on. evoq_consistency asks it to derive what a strong dispatch must wait for; nothing keeps a list.

route_event(Event, Metadata)

-spec route_event(map(), map()) -> ok.

Route an event to interested handlers.

route_event(Event, Metadata, Opts)

-spec route_event(map(), map(), map()) -> ok.

Route an event with options.

targets => [pid()] delivers to exactly those handlers instead of every handler registered for the type. The store subscription uses it: it delivers a store's events only to handlers whose history from that store it has sent, and a late handler's history to that handler alone (evoq #4).

route_events(Events, Metadata)

-spec route_events([map()], map()) -> ok.

Route multiple events to interested handlers.

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

Start the event router.