event_bus v1.3.0 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
Functions
Fetch event data
Send the event processing completed to the Observation Manager
Send the event processing skipped to the Observation Manager
Send event to all subscribers(listeners)
Register a topic
Subscribe to the bus
Is given listener subscribed to the bus for the given topics?
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
Fetch event data
Examples
EventBus.fetch_event({:hello_received, "123"})
Send the event processing completed to the Observation Manager
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
Send the event processing skipped to the Observation Manager
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 event to all subscribers(listeners).
Examples
event = %Event{id: 1, topic: :webhook_received,
data: %{"message" => "Hi all!"}}
EventBus.notify(event)
: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
Is given listener subscribed to the bus for the given topics?
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 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, %{}}]