Simple in-process pub/sub event bus.
In production replace with Phoenix.PubSub, Broadway, or a message broker.
Usage
DDD.EventBus.subscribe(MyApp.Events.OrderPlaced, MyApp.Handlers.SendEmail)
DDD.EventBus.publish(event)
defmodule MyApp.Handlers.SendEmail do
def handle(%MyApp.Events.OrderPlaced{} = event) do
MyApp.Mailer.send_confirmation(event.customer_id)
end
end
Summary
Functions
Returns a specification to start this module under a supervisor.
Handler modules subscribed to an event type, in subscription order.
Callback implementation for GenServer.init/1.
Publish a single domain event.
Publish a list of domain events.
Subscribe a handler module to an event type. Subscribing twice has no extra effect.
Remove a handler's subscription to an event type.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Handler modules subscribed to an event type, in subscription order.
Callback implementation for GenServer.init/1.
Publish a single domain event.
Publish a list of domain events.
Subscribe a handler module to an event type. Subscribing twice has no extra effect.
Remove a handler's subscription to an event type.