View Source WhiteRabbit.Consumer (White Rabbit v0.2.0)

Consumer GenServer that will handle connecting to a channel using a configured connection and then declare an exchange and queue to handle messages from a RabbitMQ broker server.

This module should only be concerned about establishing channels and registering itself as a consumer.

Actual processing of incoming messages are handled externally through configerd processors. See WhiteRabbit.Processor behavior.

start-under-a-supervisor-with-child_spec

Start under a supervisor with child_spec:

children = [
  %{
    id: :WhiteRabbitConsumer,
    start:
      {WhiteRabbit.Consumer, :start_link,
       [
         %WhiteRabbit.Consumer{
           name: :WhiteRabbitConsumer,
           exchange: "WhiteRabbitConsumer_exchange",
           queue: "WhiteRabbitConsumer_queue"
         }
       ]}
  },
]

Supervisor.init(children, strategy: :one_for_one)

starting-under-the-fluffle-dynamic-superviser

Starting under the Fluffle dynamic superviser

DynamicSupervisor.start_child(
  AppOne.WhiteRabbit.Fluffle.DynamicSupervisor.Consumer,
  {WhiteRabbit.Consumer, %WhiteRabbit.Consumer{
      owner_module: AppOne.WhiteRabbit,
      connection_name: :appone_connection,
      name: "AppOne.JsonConsumer",
      exchange: "json_test_exchange",
      queue: "json_test_queue",
      processor: %WhiteRabbit.Processor.Config{module: AppOne.TestJsonProcessor}
    }
  }
)

To Do:

Maybe even include a handle_info function that can dynamically spawn more workers on demand by a specific message payload.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Handle incoming channel_monitor messages to allow for recovering of down channels

Register process as consumer.

Start a number of Consumer with the given config.

Start a WhiteRabbit Consumer Genserver.

Link to this section Types

@type t() :: %WhiteRabbit.Consumer{
  binding_keys: [String.t()],
  channel_name: String.t(),
  channel_registry: term(),
  connection_name: Sting.t(),
  error_queue: boolean(),
  exchange: String.t(),
  exchange_type: atom(),
  name: t(),
  owner_module: module(),
  prefetch_count: integer(),
  processor: WhiteRabbit.Processor.Config.t(),
  queue: String.t(),
  queue_opts: Keyword.t(),
  uuid_name: String.t()
}

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Handle incoming channel_monitor messages to allow for recovering of down channels

Link to this function

register_consumer(pid, active_channel, args)

View Source

Register process as consumer.

Returns {:ok, %{channel: active_channel, consumer_tag: consumer_tag}} if succesful.

Monitors the active AMQP Channel process pid to allow parent process to handle incoming :DOWN messages.

Sets the prefetch_count for the given connection as well.

Link to this function

register_name(name, registry_name \\ WhiteRabbit.Fluffle.FluffleRegistry)

View Source
Link to this function

start_dynamic_consumers(config, concurrency, owner_module)

View Source
@spec start_dynamic_consumers(
  config :: t(),
  concurrency :: integer(),
  owner_module :: module()
) :: [tuple()]

Start a number of Consumer with the given config.

Pass a WhiteRabbit.Consumer{} to start it under a DynamicSupervisor.

Optionally pass an integer as the second argument to start any number of Consumers with the same config.

Start a WhiteRabbit Consumer Genserver.