event_bus v1.0.0-beta3 EventBus

Traceable event bus implementation for Elixir with builtin event store and event watcher based on ETS

Link to this section Summary

Functions

Fetch event data

Send the event processing completed to the watcher

Send the event processing skipped to the watcher

Send event to all listeners

Register a topic

Subscribe to the bus

List the subscribers

List the subscribers to the with given topic

Check if topic registered

List all registered topics

Unregister a topic

Unsubscribe from the bus

Link to this section Functions

Link to this function fetch_event(event_shadow)
fetch_event({atom, String.t | integer}) :: EventBus.Model.Event.t

Fetch event data

Examples

EventBus.fetch_event({:hello_received, "123"})
Link to this function mark_as_completed(listener_with_event_shadow)
mark_as_completed({tuple | module, atom, String.t | integer}) :: no_return

Send the event processing completed to the watcher

Examples

EventBus.mark_as_completed({MyEventListener, :hello_received, "123"})

# For configurable listeners you must pass tuple of listener and config
my_config = %{}
listener = {OtherListener, my_config}
EventBus.mark_as_completed({listener, :hello_received, "124"})
:ok
Link to this function mark_as_skipped(listener_with_event_shadow)
mark_as_skipped({tuple | module, atom, String.t | integer}) :: no_return

Send the event processing skipped to the watcher

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
Link to this function notify(event)
notify(EventBus.Model.Event.t) :: :ok

Send event to all listeners.

Examples

event = %Event{id: 1, topic: :webhook_received,
  data: %{"message" => "Hi all!"}}
EventBus.notify(event)
:ok
Link to this function register_topic(topic)
register_topic(String.t | atom) :: boolean

Register a topic

Examples

EventBus.register_topic(:demo_topic)
:ok
Link to this function subscribe(listener_with_topics)
subscribe(tuple) :: :ok

Subscribe to the 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
Link to this function subscribers()
subscribers() :: [any]

List the subscribers.

Examples

EventBus.subscribers()
[MyEventListener]

# One usual and one configured listener with its config
EventBus.subscribers()
[MyEventListener, {OtherListener, %{}}]
Link to this function subscribers(topic)
subscribers(atom | String.t) :: [any]

List the subscribers to the with given topic.

Examples

EventBus.subscribers(:metrics_received)
[MyEventListener]

# One usual and one configured listener with its config
EventBus.subscribers(:metrics_received)
[MyEventListener, {OtherListener, %{}}]
Link to this function topic_exist?(topic)
topic_exist?(String.t | atom) :: boolean

Check if topic registered.

Examples

EventBus.topic_exist?(:demo_topic)
true
Link to this function topics()
topics() :: [atom]

List all registered topics.

Examples

EventBus.topics()
[:metrics_summed]
Link to this function unregister_topic(topic)
unregister_topic(String.t | atom) :: boolean

Unregister a topic

Examples

EventBus.unregister_topic(:demo_topic)
:ok
Link to this function unsubscribe(listener)
unsubscribe({tuple | module}) :: :ok

Unsubscribe from the bus.

Examples

EventBus.unsubscribe(MyEventListener)
:ok

# For configurable listeners you must pass tuple of listener and config
my_config = %{}
EventBus.unsubscribe({{OtherListener, my_config}})
:ok