ConduitAMQP
An AMQP adapter for Conduit.
Installation
This package can be installed as:
Add
conduit_amqp
to your list of dependencies inmix.exs
:def deps do [{:conduit_amqp, "~> 0.1.0"}] end
Ensure
conduit_amqp
is started before your application:def application do [applications: [:conduit_amqp]] end
Configuring the Adapter
# config/config.exs
config :my_app, MyApp.Broker,
adapter: ConduitAMQP,
url: "amqp://my_app:secret@my-rabbit-host.com"
For the full set of options, see ConduitAQMP
.
Configuring Exchanges
You can define exchanges with the exchange
macro in the
configure
block of your Broker. The exchange
macro accepts
the name of the exchange and options for the exchange.
Options
:type
: Either:topic
,:fanout
,:direct
, or:headers
. Defaults to:topic
.:durable
: If set, keeps the Exchange between restarts of the broker. Defaults tofalse
.:auto_delete
: If set, deletes the Exchange once all queues unbind from it. Defaults tofalse
.:passive
: If set, returns an error if the Exchange does not already exist. Defaults tofalse
.:internal:
If set, the exchange may not be used directly by publishers. Defaults tofalse
.
Example
defmodule MyApp.Broker do
use Conduit.Broker, otp_app: :my_app
configure do
exchange "my.topic", type: "topic", durable: true
end
end
Configuring Queues
You can define queues with the queue
macro in the
configure
block of your Broker. The queue
macro accepts
the name of the queue and options for the exchange.
Options
:durable
- If set, keeps the Queue between restarts of the broker. Defaults tofalse
.:auto-delete
- If set, deletes the Queue once all subscribers disconnect. Defaults tofalse
.:exclusive
- If set, only one subscriber can consume from the Queue. Defaults tofalse
.:passive
- If set, raises an error unless the queue already exists. Defaults tofalse
.:from
- A list of routing keys to bind the queue to.:exchange
- Name of the exchange used to bind the queue to the routing keys.
Example
defmodule MyApp.Broker do
use Conduit.Broker, otp_app: :my_app
configure do
queue "my.queue", from: ["#.created.user"], exchange: "amq.topic", durable: true
end
end
Publishing Messages
TODO
Special Headers
TODO
Architecture
When ConduitAMQP is used as an adapter for Conduit, it starts ConduitAMQP as a child supervisor. ConduitAMQP starts:
- ConduitAQMP.ConnPool - Creates and supervises a pool of AMQP connections.
- ConduitAMQP.PubSub - Creates and supervises ConduitAMQP.PubPool and ConduitAMQP.SubPool.
- ConduitAMQP.Subscribers - A supervisor for subscribers that process messages.