event_bus v1.5.2 EventBus
Traceable, extendable and minimalist event bus implementation for Elixir with built-in event store and event observation manager based on ETS
Link to this section Summary
Types
EventBus.Model.Event struct
Event id
Tuple of topic name and event id
Event listener
Listener configuration
List of event listeners
Event listener with config
Tuple of listener and event reference
Tuple of listener and event shadow
Tuple of listener, topic and event id
Tuple of listener and list of topic patterns
Event listener without config
Topic name
List of topic names
Regex pattern to match topic name
List of topic patterns
Functions
Fetch an event
Fetch an event’s data
Mark the event as completed for the listener
Mark the event as skipped for the listener
Send an event to all subscribers(listeners)
Register a topic
Subscribe a listener to the event bus
Check if the given listener subscribed to the event bus for the given topic patterns
List the subscribers
List the subscribers for the given topic
Check if a topic registered
List all the registered topics
Unregister a topic
Unsubscribe a listener from the event bus
Link to this section Types
EventBus.Model.Event struct
Event id
Tuple of topic name and event id
Event listener
Listener configuration
List of event listeners
Event listener with config
listener_with_event_ref() :: listener_with_event_shadow() | listener_with_topic_and_event_id()
Tuple of listener and event reference
listener_with_event_shadow() :: {listener(), event_shadow()}
Tuple of listener and event shadow
Tuple of listener, topic and event id
listener_with_topic_patterns() :: {listener(), topic_pattern_list()}
Tuple of listener and list of topic patterns
Event listener without config
Topic name
List of topic names
Regex pattern to match topic name
List of topic patterns
Link to this section Functions
mark_as_completed(listener_with_event_ref()) :: :ok
Mark the event as completed for the listener
Examples
topic = :hello_received
event_id = "124"
event_shadow = {topic, event_id}
# For regular listeners
EventBus.mark_as_completed({MyEventListener, event_shadow})
# For configurable listeners you must pass tuple of listener and config
my_config = %{}
listener = {OtherListener, my_config}
EventBus.mark_as_completed({listener, event_shadow})
:ok
mark_as_skipped(listener_with_event_ref()) :: :ok
Mark the event as skipped for the listener
Examples
EventBus.mark_as_skipped({MyEventListener, {:unmatched_occurred, "124"}})
# For configurable listeners you must pass tuple of listener and config
my_config = %{}
listener = {OtherListener, my_config}
EventBus.mark_as_skipped({listener, {:unmatched_occurred, "124"}})
:ok
Send an event to all subscribers(listeners)
Examples
event = %Event{id: 1, topic: :webhook_received,
data: %{"message" => "Hi all!"}}
EventBus.notify(event)
:ok
subscribe(listener_with_topic_patterns()) :: :ok
Subscribe a listener to the event bus
Examples
EventBus.subscribe({MyEventListener, [".*"]})
:ok
# For configurable listeners you can pass tuple of listener and config
my_config = %{}
EventBus.subscribe({{OtherListener, my_config}, [".*"]})
:ok
subscribed?(listener_with_topic_patterns()) :: boolean()
Check if the given listener subscribed to the event bus for the given topic patterns
Examples
EventBus.subscribe({MyEventListener, [".*"]})
:ok
EventBus.subscribed?({MyEventListener, [".*"]})
true
EventBus.subscribed?({MyEventListener, ["some_initialized"]})
false
EventBus.subscribed?({AnothEventListener, [".*"]})
false
List the subscribers
Examples
EventBus.subscribers()
[MyEventListener]
# One usual and one configured listener with its config
EventBus.subscribers()
[MyEventListener, {OtherListener, %{}}]
List the subscribers for the given topic
Examples
EventBus.subscribers(:metrics_received)
[MyEventListener]
# One usual and one configured listener with its config
EventBus.subscribers(:metrics_received)
[MyEventListener, {OtherListener, %{}}]