Rabbit
Rabbit is a set of tools for building applications with RabbitMQ.
Installation
The package can be installed by adding rabbit
to your list of dependencies in mix.exs
:
def deps do
[
{:rabbit, "~> 0.1"}
]
end
Documentation
Please see HexDocs for additional documentation.
Example
Create a connection module:
defmodule MyConnection do
use Rabbit.Connection
# Callbacks
# Perform runtime config
def init(opts) do
{:ok, opts}
end
end
MyConnection.start_link()
Create a consumer module:
defmodule MyConsumer do
use Rabbit.Consumer
# Callbacks
# Perform runtime config
def init(opts) do
{:ok, opts}
end
# Perform any exchange or queue setup
def after_connect(channel, queue) do
AMQP.Queue.declare(channel, queue)
:ok
end
# Handle message consumption
def handle_message(message) do
IO.inspect(message.payload)
{:ack, message}
end
# Handle message errors
def handle_error(message) do
{:nack, message}
end
end
MyConsumer.start_link(MyConnection, queue: "my_queue", prefetch_count: 10)
Create a producer module:
defmodule MyProducer do
use Rabbit.Producer
# Callbacks
# Perform runtime config
def init(opts) do
{:ok, opts}
end
end
MyProducer.start_link(MyConnection)
MyProducer.publish("", "my_queue", "hello")