channels v0.0.1 Channels.Context.Spec

This modules parses context specification.

A context specification defines how exchanges, queues or any broker related resources must be declared or configured before an AMQP process interacts with them.

Example

Imagine you defined a connection named :my_connection on your Mix config:

config :channels,

...
connections: [:my_connection]

config :channels, :my_connection,

host: "localhost",
port: 1234
...

This is an example of possible configuration for a consumer that subscribes to a queue “my_queue” to the direct exchange “my_exchange” only for the routing_key “the_key” through the previously defined connection:

[

connection: :my_connection,
exchange: [
  name: "my_exchange",
  type: :direct,
  opts: [durable: true]
],
queue: [
  name: "my_queue",
  opts: [durable: true, exclusive: true]
],
bind: [routing_key: "the_key"]

]

Summary

Functions

Returns the binding configuration. It is optional. By default it is an empty keyword list

Returns a new Spec struct given a configuration

Returns the exchange configuration. It expects at least the following fields

Returns a new Spec struct given a configuration

Returns the queue configuration. It expects at least the name field

Types

t :: %Channels.Context.Spec{spec: spec}

Functions

bind_opts(spec)

Specs

bind_opts(t) :: {:ok, %{opts: Keyword.t}}

Returns the binding configuration. It is optional. By default it is an empty keyword list.

bind: [routing_key: "my_key", ...]

It can include a set of option to be given to the adapter when binding the queue and the exchange.

conn_name(spec)

Specs

conn_name(t) ::
  {:ok, name :: atom} |
  {:error, reason :: term}

Returns a new Spec struct given a configuration

exchange(spec)

Specs

exchange(t) ::
  {:ok, %{name: binary, type: atom, opts: Keyword.t}} |
  {:error, reason :: term}

Returns the exchange configuration. It expects at least the following fields:

exchange: [name: "exchange_name", type: :direct]

Also it can include an :opts field which is a keyword list of options to be given to the adapter when declaring the exchange.

new(spec)

Specs

new(spec) :: t

Returns a new Spec struct given a configuration

queue(spec)

Specs

queue(t) ::
  {:ok, %{name: binary, opts: Keyword.t}} |
  {:error, reason :: term}

Returns the queue configuration. It expects at least the name field:

queue: [name: "queue_name"]

Also it can include an :opts field which is a keyword list of options to be given to the adapter when declaring the queue.