evoq_event_handler behaviour (evoq v1.30.1)
View SourceEvent handler behavior for evoq.
Event handlers subscribe to event types (NOT streams) and process events as they are published. This is the key scalability improvement over per-stream subscriptions.
Callbacks
Required: - interested_in() -> [binary()] Returns list of event types this handler processes
- init(Config) -> {ok, State} Initialize handler state
- handle_event(EventType, Event, Metadata, State) -> {ok, NewState} | {error, Reason} Process a single event
Optional: - on_error(Error, Event, FailureContext, State) -> error_action() Handle errors during event processing
- replay_policy() -> skip | deliver What to do with REPLAY: events this node had already consumed before it restarted, which evoq_store_subscription hands out again on every boot with replaying => true in the metadata. skip for a handler with side effects (publishing, sending, dispatching), which would otherwise repeat every one of them on every restart. deliver for a handler rebuilding in-memory state from history.
Not declaring it delivers, as before this callback existed, and logs one warning per boot naming the handler the first time it is handed replay: a handler with side effects and no policy is the one to find.
- handle_info(Info, State) -> {noreply, NewState} | {stop, Reason, NewState} Any other message the handler process receives, most usefully one it scheduled to itself from handle_event/4 (a retry via send_after). Same shape as gen_server's. A handler without it that is sent a message logs a warning naming itself and the message.
Summary
Functions
Get event types this handler is interested in.
Notify handler of an event.
Start an event handler.
Start an event handler with options.
Callbacks
-callback interested_in() -> [EventType :: binary()].
-callback on_error(Error :: term(), Event :: map(), FailureContext :: #evoq_failure_context{handler_module :: atom(), event :: map(), error :: term(), attempt_number :: pos_integer(), first_failure_at :: integer(), last_failure_at :: integer(), first_failure_mono :: integer(), last_failure_mono :: integer(), stacktrace :: list()}, State :: term()) -> evoq_error_handler:error_action().
-callback replay_policy() -> skip | deliver.
Functions
Get event types this handler is interested in.
Notify handler of an event.
Start an event handler.
Start an event handler with options.