conejo v0.5.0 Conejo.Consumer behaviour View Source

Conejo.Consumer is the behaviour which will help you to implement your own RabbitMQ consumers.

Configuration

Conejo.Consumer needs a configuration in the environment files.

Example:

config :my_application, :consumer,
  exchange: "my_exchange",
  exchange_type: "topic",
  queue_name: "my_queue",
  queue_declaration_options: [{:auto_delete, true}, {:exclusive, true}],
  queue_bind_options: [routing_key: "example"],
  consume_options: [no_ack: true]

Definition

defmodule MyConsumer do
  use Conejo.Consumer

  def handle_consume(_channel, payload, _params) do
    IO.inspect payload
  end
end

Start Up

  options = Application.get_all_env(:my_application)[:consumer]
  {:ok, consumer} = MyConsumer.start_link(options, [name: :consumer])

Link to this section Summary

Callbacks

It will be executed after a message is received in an independant process

Link to this section Types

Link to this type ack_opts() View Source
ack_opts() :: [{:multiple, boolean()}]
Link to this type channel() View Source
channel() :: AMQP.Channel
Link to this type nack_opts() View Source
nack_opts() :: [multiple: boolean(), requeue: boolean()]
Link to this type params() View Source
params() :: %{}
Link to this type payload() View Source
payload() :: any()
Link to this type reject_opts() View Source
reject_opts() :: [{:requeue, boolean()}]

Link to this section Callbacks

Link to this callback handle_consume(channel, payload, params) View Source
handle_consume(channel(), payload(), params()) ::
  :ack
  | {:ack, ack_opts()}
  | :nack
  | {:nack, nack_opts()}
  | :reject
  | {:reject, reject_opts()}
  | any()

It will be executed after a message is received in an independant process.

  • payload: The received message.
  • params: All the available parameters related to the received message.

It has to return:

  • If there is acknowledge:

    • :ack
    • {:ack, ack_opts}
    • :nack
    • {:nack, nack_opts}
    • :reject
    • {:reject, reject_opts} where the options are Keyword lists like : [multiple: boolean, requeue: boolean]
  • If there is no acknowledge:

    • Any other value