EventBusHandler v0.1.0 EventBusHandler behaviour View Source
Handles :event_bus
subscriptions.
You just need to define a subscription handler module:
defmodule MyApp.SomeEventHandler do
use EventBusHandler, topics: ["some_topic_*"]
# with :topics key you specify topics to which the handler will be
# subscribed, i.e. to every topic, starting with "some_topic_".
alias EventBus.Model.Event
def handle(:some_topic_1, %Event{data: data} = event) do
# Here goes your handling of an event on topic :your_topic_1
# If you for some reason want to skip handling (i.e. mark the event as
# skipped), return `:skip` or something. Then warning will appear that
# an event with this topic was skipped, and the returned tag will be
# shown. Otherwise, just return `:ok`.
:ok
end
end
Create a config module and start it from your application:
defmodule MyApp.EventBusHandler do
use EventBusHandler, handlers: [YourEventHandler]
end
# ...
def start(_type, _args) do
children = [
Florissimo.Repo,
FlorissimoWeb.Endpoint,
# In the code below, in key :handlers you specify all defined event
# handlers.
EventBusHandler
]
# ...
All the tasks will be started in its own process under a supervisor. For every handler module separate supervisor is created.
Link to this section Summary
Callbacks
Event handler for the topic
Link to this section Types
Link to this section Callbacks
Specs
handle(topic(), event()) :: :ok | error_reason()
Event handler for the topic