conejo v0.6.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 section Callbacks
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