View Source Solvent.Subscriber behaviour (solvent v0.3.0)
A module shorthand for defining subscribers.
Use this module to quickly create a module that can handle Solvent events.
defmodule MyModule do
use Solvent.Subscriber, filters: [exact: [type: "myevent.published"]]
def handle_event(type, event_id) do
# Fetch and handle your event here
end
end
Then you only need to pass in the module name to Solvent.subscribe/1
,
usually done in your application.ex
, or wherever your code starts.
By default, module subscribers will automatically call Solvent.EventStore.ack/2
once handle_event/2
returns.
To disable this feature, set the :auto_ack
option to false
, and then you can acknowledge the event manually.
This module provides an auto_ack/1
function that is compiled with the ID of your handler,
so you only need to provide the event ID.
defmodule MyModule do
use Solvent.Subscriber,
filters: [prefix: [type: "myevents."]],
auto_ack: false
def handle_event(type, event_id) do
# Fetch and handle your event here
ack_event(event_id)
end
end
Using this module also imports Solvent.Subscriber.event!/1
which unwraps the result from Solvent.EventStore.fetch/1
and raises if the event is not found.
options
Options
:filters
- the filter expression to match events against:id
- the ID to give the subscriber function. Defaults to the current module name.:auto_ack
- automatically callSubscriber.EventStore.ack/1
afterhandle_event/2
returns. Defaults totrue
.
Link to this section Summary
Callbacks
Returns the filter to match events against.
Performs an action when given an event type and event ID.
Returns the current subscriber ID.
Functions
Unwraps the result from Solvent.EventStore.fetch/1
and raises if the event is not found.
Link to this section Callbacks
@callback filter() :: String.t()
Returns the filter to match events against.
This function is automatically created when you use
this module,
but you can override it, if you need.
Performs an action when given an event type and event ID.
@callback subscriber_id() :: String.t()
Returns the current subscriber ID.
This function is automatically created when you use
this module,
but you can override it, if you need.
Link to this section Functions
Unwraps the result from Solvent.EventStore.fetch/1
and raises if the event is not found.