Packages

build microservices with Kafka + Avro schemas

Current section

Files

Jump to
kaufmann_ex lib stages consumer.ex
Raw

lib/stages/consumer.ex

defmodule KaufmannEx.Stages.Consumer do
@moduledoc """
A consumer will be a consumer supervisor that will
Subscriber tasks for each event.
"""
require Logger
use ConsumerSupervisor
def start_link() do
:ok = Logger.info(fn -> "#{__MODULE__} Starting" end)
ConsumerSupervisor.start_link(__MODULE__, :ok)
end
# Callbacks
def init(:ok) do
children = [
worker(KaufmannEx.Stages.EventHandler, [], restart: :temporary)
]
# max_demand is highly resource dependent
{:ok, children,
strategy: :one_for_one,
subscribe_to: [
{KaufmannEx.Stages.Producer, max_demand: KaufmannEx.Config.event_handler_demand()}
]}
end
end