spotter v0.3.0 Spotter.AMQP.Connection.Helper

Helper functions to manage connections with AMQP.

This module produces verbose debug logs.

Link to this section Summary

Functions

Bind AMQP queue to Exchange

Gracefully close AMQP channel

Declare AMQP exchange. Exchange is durable whenever queue is durable

Declare AMQP queue. You can omit error_queue, then dead letter queue won’t be created. Dead letter queue is hardcoded to be durable

Same as open_channel!/1, but returns {:ok, connection} or {:error, reason} tuples

Open new AMQP channel inside a connection

Same as open_connection!/1, but returns {:ok, connection} or {:error, reason} tuples

Open AMQP connection

Set channel QOS policy. Especially useful when you want to limit number of unacknowledged request per worker

Link to this section Functions

Link to this function bind_queue(channel, queue, exchange, opts)

Bind AMQP queue to Exchange.

See: https://hexdocs.pm/amqp/AMQP.Queue.html#bind/4

Link to this function close_channel(channel)

Gracefully close AMQP channel.

Link to this function declare_exchange(channel, exchange, type \\ :direct, opts \\ [])

Declare AMQP exchange. Exchange is durable whenever queue is durable.

Types:

  • :direct - direct exchange.
  • :fanout - fanout exchange.
  • :topic - topic exchange.
  • :headers - headers exchange.

See: https://hexdocs.pm/amqp/AMQP.Queue.html#declare/3

Link to this function declare_queue(channel, queue, error_queue, opts)

Declare AMQP queue. You can omit error_queue, then dead letter queue won’t be created. Dead letter queue is hardcoded to be durable.

Options

  • :durable - If set, keeps the Queue between restarts of the broker
  • :auto-delete - If set, deletes the Queue once all subscribers disconnect
  • :exclusive - If set, only one subscriber can consume from the Queue
  • :passive - If set, raises an error unless the queue already exists

See: https://hexdocs.pm/amqp/AMQP.Queue.html#declare/3

Link to this function open_channel(connection)

Same as open_channel!/1, but returns {:ok, connection} or {:error, reason} tuples.

Link to this function open_channel!(connection)

Open new AMQP channel inside a connection.

See: https://hexdocs.pm/amqp/AMQP.Channel.html#open/1

Link to this function open_connection(opts)

Same as open_connection!/1, but returns {:ok, connection} or {:error, reason} tuples.

Link to this function open_connection!(connection_opts)

Open AMQP connection.

Options

  • :username - The name of a user registered with the broker (defaults to “guest”);
  • :password - The password of user (defaults to “guest”);
  • :virtual_host - The name of a virtual host in the broker (defaults to “/“);
  • :host - The hostname of the broker (defaults to “localhost”);
  • :port - The port the broker is listening on (defaults to 5672);
  • :channel_max - The channel_max handshake parameter (defaults to 0);
  • :frame_max - The frame_max handshake parameter (defaults to 0);
  • :heartbeat - The hearbeat interval in seconds (defaults to 0 - turned off);
  • :connection_timeout - The connection timeout in milliseconds (defaults to 15_000);
  • :ssl_options - Enable SSL by setting the location to cert files (defaults to none);
  • :client_properties - A list of extra client properties to be sent to the server, defaults to [];
  • :socket_options - Extra socket options. These are appended to the default options. See http://www.erlang.org/doc/man/inet.html#setopts-2 and http://www.erlang.org/doc/man/gen_tcp.html#connect-4 for descriptions of the available options.

See: https://hexdocs.pm/amqp/AMQP.Connection.html#open/1

Link to this function set_channel_qos(channel, opts)

Set channel QOS policy. Especially useful when you want to limit number of unacknowledged request per worker.

Options

  • :prefetch_size - Limit of unacknowledged messages (in bytes).
  • :prefetch_count - Limit of unacknowledged messages (count).
  • :global - If global is set to true this applies to the entire Connection, otherwise it applies only to the specified Channel.

See: https://hexdocs.pm/amqp/AMQP.Basic.html#qos/2