View Source Solvent.Subscriber behaviour (solvent v0.1.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, match_type: ~r/myevents.*/
def handle_event(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/1
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,
match_type: ~r/myevents.*/,
auto_ack: false
def handle_event(event_id) do
# Fetch and handle your event here
ack_event(event_id)
end
end
options
Options
:id
- the ID to give the subscriber function. Defaults to the current module name.:match_type
- a string or regex to match event types. Defaults to~r/.*/
, which will match every event.:auto_ack
- automatically callSubscriber.EventStore.ack/1
afterhandle_event/1
returns. Defaults totrue
.
Link to this section Summary
Callbacks
Performs an action when given an event ID.
Returns the value to match event types against.
Returns the current subscriber ID.
Link to this section Callbacks
Performs an action when given an event ID.
@callback match_type() :: String.t()
Returns the value to match event types against.
This function is automatically created when you use
this module,
but you can override it, if you need.
@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.