DDD.EventBus (vicander v0.1.1)

Copy Markdown View Source

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

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

handlers_for(event_module)

Handler modules subscribed to an event type, in subscription order.

init(state)

Callback implementation for GenServer.init/1.

publish(event)

Publish a single domain event.

publish_all(events)

Publish a list of domain events.

start_link(opts \\ [])

subscribe(event_module, handler_module)

Subscribe a handler module to an event type. Subscribing twice has no extra effect.

unsubscribe(event_module, handler_module)

Remove a handler's subscription to an event type.