Conejo

hex.pmhexdocs.pmBuild Status

Conejo is an OTP application/library based on pma/amqp which will help you to define your AMQP/RabbitMQ publishers and consumers in an easier way.

I highly recommend to initiate your publishers/consumers under a Supervisor.

Installation

Configuration

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]
config :conejo,
host: "my_host",
port: 5672,
username: "user",
password: "pass"

Confex is supported.

Consumer

defmodule MyApplication.MyConsumer do
use Conejo.Consumer
def handle_consume(_channel, payload, _params) do
IO.puts "Received -> #{inspect payload}"
end
end
options = Application.get_all_env(:my_application)[:consumer]
{:ok, consumer} = MyApplication.MyConsumer.start_link(options, [name: :consumer])

Publisher

defmodule MyApplication.MyPublisher do
use Conejo.Publisher
end
{:ok, publisher} = MyApplication.MyPublisher.start_link([], [name: :publisher])
#Synchronous
MyApplication.MyPublisher.sync_publish(:publisher, "my_exchange", "example", "Hola")
#Asynchronous
MyApplication.MyPublisher.async_publish(:publisher, "my_exchange", "example", "Adios")

Test

mix test --no-start