hare v0.2.2 Hare.Adapter behaviour

Specification of the AMQP adapter

Summary

Callbacks

Acks a message given its meta

Binds a queue to an exchange

Cancels the consumer with the given consumer_tag

Closes a channel

Closes the AMQP connection

Consumes messages from a queue

Declares a server-named queue

Gets a message from a queue

Transforms a message received by a consumed pid into one of the well defined terms expected by consumers

Links the caller to the process representing the channel

Monitors the process representing the channel

Monitors the process representing the AMQP connection

Nacks a message given its meta

Opens a channel through the given connection

Establishes connection with the AMQP server using the given config

Purges all messages in a queue

Sets the Quality Of Service of the channel

Rejects a message given its meta

Unbinds a queue from an exchange

Unlinks the caller to the process representing the channel

Types

chan()
chan() :: term
conn()
conn() :: term
consumer_tag()
consumer_tag() :: binary
exchange_name()
exchange_name() :: binary
exchange_type()
exchange_type() :: atom
meta()
meta() :: map
opts()
opts() :: Keyword.t
payload()
payload() :: binary
queue_name()
queue_name() :: binary
routing_key()
routing_key() :: binary
t()
t() :: module

Callbacks

ack(chan, meta, opts)
ack(chan, meta, opts) :: :ok

Acks a message given its meta

bind(chan, queue_name, exchange_name, opts)
bind(chan, queue_name, exchange_name, opts) :: :ok

Binds a queue to an exchange

cancel(chan, consumer_tag, opts)
cancel(chan, consumer_tag, opts) :: :ok

Cancels the consumer with the given consumer_tag

close_channel(chan)
close_channel(chan) :: :ok

Closes a channel

close_connection(conn)
close_connection(conn) :: :ok

Closes the AMQP connection.

consume(chan, queue_name, pid, opts)
consume(chan, queue_name, pid, opts) :: {:ok, consumer_tag}

Consumes messages from a queue.

Once a pid is consuming a queue status messages and actual queue messages must be sent to the consuming pid as elixir messages in a adapter-specific format.

The function handle/2 should receive that elixir messages and transform them into well defined terms.

declare_exchange(chan, exchange_name, exchange_type, opts)
declare_exchange(chan, exchange_name, exchange_type, opts) ::
  :ok |
  {:error, reason :: term}

Declares an exchange

declare_queue(chan, queue_name, opts)
declare_queue(chan, queue_name, opts) ::
  {:ok, info :: term} |
  {:error, term}

Declares a queue

declare_server_named_queue(chan, opts)
declare_server_named_queue(chan, opts) ::
  {:ok, queue_name, info :: term} |
  {:error, term}

Declares a server-named queue

delete_exchange(chan, exchange_name, opts)
delete_exchange(chan, exchange_name, opts) :: :ok

Deletes an exchange

delete_queue(chan, queue_name, opts)
delete_queue(chan, queue_name, opts) :: {:ok, info :: term}

Deletes a queue

get(chan, queue_name, opts)
get(chan, queue_name, opts) ::
  {:empty, info :: map} |
  {:ok, payload, meta}

Gets a message from a queue

handle(message)
handle(message :: term) ::
  {:consume_ok, meta} |
  {:deliver, payload, meta} |
  {:cancel_ok, meta} |
  {:cancel, meta} |
  :unknown

Transforms a message received by a consumed pid into one of the well defined terms expected by consumers.

The expected terms are:

  • {:consume_ok, meta} - consume-ok message sent by the AMQP server when a consumer is started
  • {:deliver, payload, meta} - an actual message from the queue being consumed
  • {:cancel_ok, meta} - cancel-ok message sent by the AMQP server when a consumer is started
  • {:cancel, meta} - cancel message sent by the AMQP server when a consumer has been unexpectedly closed
  • :unknown - any other message
monitor_channel(chan)
monitor_channel(chan) :: reference

Monitors the process representing the channel

monitor_connection(conn)
monitor_connection(conn) :: reference

Monitors the process representing the AMQP connection.

nack(chan, meta, opts)
nack(chan, meta, opts) :: :ok

Nacks a message given its meta

open_channel(conn)
open_channel(conn) :: {:ok, chan} | {:error, term}

Opens a channel through the given connection

open_connection(config)
open_connection(config :: term) :: {:ok, conn} | {:error, term}

Establishes connection with the AMQP server using the given config.

publish(chan, exchange_name, payload, routing_key, opts)
publish(chan, exchange_name, payload, routing_key, opts) :: :ok

Publishes a message to an exchange

purge(chan, queue_name)
purge(chan, queue_name) :: {:ok, info :: map}

Purges all messages in a queue

qos(chan, opts)
qos(chan, opts) :: :ok

Sets the Quality Of Service of the channel

reject(chan, meta, opts)
reject(chan, meta, opts) :: :ok

Rejects a message given its meta

unbind(chan, queue_name, exchange_name, opts)
unbind(chan, queue_name, exchange_name, opts) :: :ok

Unbinds a queue from an exchange