evoq_event_handler behaviour (evoq v1.14.1)

View Source

Event 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

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

handle_event/4

-callback handle_event(EventType :: binary(), Event :: map(), Metadata :: map(), State :: term()) ->
                          {ok, NewState :: term()} | {error, Reason :: term()}.

init/1

-callback init(Config :: map()) -> {ok, State :: term()} | {error, Reason :: term()}.

interested_in/0

-callback interested_in() -> [EventType :: binary()].

on_error/4

(optional)
-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(),
                                             stacktrace :: list()},
                   State :: term()) ->
                      evoq_error_handler:error_action().

Functions

get_event_types(Pid)

-spec get_event_types(pid()) -> [binary()].

Get event types this handler is interested in.

notify(Pid, EventType, Event, Metadata)

-spec notify(pid(), binary(), map(), map()) -> ok | {error, term()}.

Notify handler of an event.

start_link(HandlerModule, Config)

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

Start an event handler.

start_link(HandlerModule, Config, Opts)

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

Start an event handler with options.