Jumar.EventBus.Consumer behaviour (Jumar v0.1.0)

View Source

A GenStage ConsumerSupervisor implementation to consume events from Jumar.EventBus.Producer.

Usage

defmodule MyConsumer do
  use Jumar.EventBus.Consumer,
    producers: [MyProducer]

  def handle_event(event) do
    IO.inspect(event)
  end
end

You can also specify multiple producers to subscribe to, as well as all other options available in ConsumerSupervisor.

defmodule MyConsumer do
  use Jumar.EventBus.Consumer,
    producers: [
      {MyProducer, min_demand: 1, max_demand: 50},
      {AnotherProducer, max_demand: 200}
    ]

  def handle_event(event) do
    IO.inspect(event)
  end
end

See the ConsumerSupervisor module documentation on producers for more options.

Summary

Callbacks

handle_event(t)

@callback handle_event(Jumar.EventBus.Event.t()) :: :ok

handle_failure(t, list)

@callback handle_failure(Jumar.EventBus.Event.t(), [{:error, any()}]) :: :ok

Functions

start_link(args, opts \\ [])

Starts the consumer.