AMQPHelpers.Adapter behaviour (AMQP Helpers v1.6.0)

View Source

A behaviour for the AMQP client implementation.

This module declares a behaviour for the AMQP library, allowing us to use different implementations of the underlaying AMQP interface. Check out the AMQPHelpers.Adapters.Stub and AMQPHelpers.Adapters.AMQP for actual implementations of this behaviour.

This behaviour also enables us to mock this interface in tests using libraries like Mox. Check out the libraries tests for examples about this usage.

Summary

Callbacks

Acknowledges one or more messages.

Stops the given consumer from consuming.

Closes an open Channel.

Registers a queue consumer process.

Activates publishing confirmations on the channel.

Provides an easy way to access an AMQP.Channel.t/0.

Provides an easy way to access an AMQP.Connection.t/0.

Returns the next message sequence number.

Negative acknowledges of one or more messages.

Opens a new channel in a previously opened connection.

Publishes a message to an Exchange.

Register a handler for confirms on channel.

Registers a handler to deal with returned messages.

Sets the message prefetch count or prefetch size.

Callbacks

ack(channel, delivery_tag, options)

@callback ack(
  channel :: AMQP.Channel.t(),
  delivery_tag :: integer(),
  options :: keyword()
) ::
  :ok | {:error, term()}

Acknowledges one or more messages.

See AMQP.Basic.ack/3.

cancel_consume(channel, consumer_tag, opts)

@callback cancel_consume(
  channel :: AMQP.Channel.t(),
  consumer_tag :: String.t(),
  opts :: keyword()
) :: {:ok, String.t()} | {:error, term()}

Stops the given consumer from consuming.

See AMQP.Basic.cancel/3.

close_channel(channel)

@callback close_channel(channel :: AMQP.Channel.t()) :: :ok | {:error, term()}

Closes an open Channel.

See AMQP.Channel.close/1.

consume(channel, queue, consumer, options)

@callback consume(
  channel :: AMQP.Channel.t(),
  queue :: String.t(),
  consumer :: pid() | nil,
  options :: keyword()
) :: {:ok, String.t()} | AMQP.Basic.error()

Registers a queue consumer process.

See AMQP.Basic.consume/4.

enable_select_confirm(channel)

@callback enable_select_confirm(channel :: AMQP.Channel.t()) :: :ok | {:error, any()}

Activates publishing confirmations on the channel.

See AMQP.Confirm.select/1.

fetch_application_channel(name)

@callback fetch_application_channel(name :: binary() | atom()) ::
  {:ok, AMQP.Channel.t()} | {:error, any()}

Provides an easy way to access an AMQP.Channel.t/0.

See AMQP.Application.get_channel/1.

fetch_application_connection(name)

@callback fetch_application_connection(name :: binary() | atom()) ::
  {:ok, AMQP.Connection.t()} | {:error, any()}

Provides an easy way to access an AMQP.Connection.t/0.

See AMQP.Application.get_connection/1.

get_next_delivery_tag(channel)

@callback get_next_delivery_tag(channel :: AMQP.Channel.t()) :: non_neg_integer()

Returns the next message sequence number.

See AMQP.Confirm.next_publish_seqno/1.

nack(channel, delivery_tag, options)

@callback nack(
  channel :: AMQP.Channel.t(),
  delivery_tag :: integer(),
  options :: keyword()
) ::
  :ok | {:error, term()}

Negative acknowledges of one or more messages.

See AMQP.Basic.nack/3.

open_channel(connection)

@callback open_channel(connection :: AMQP.Connection.t()) ::
  {:ok, AMQP.Channel.t()} | {:error, term()}

Opens a new channel in a previously opened connection.

See AMQP.Channel.open/2.

publish(channel, exchange, routing_key, payload, options)

@callback publish(
  channel :: AMQP.Channel.t(),
  exchange :: AMQP.Basic.exchange(),
  routing_key :: AMQP.Basic.routing_key(),
  payload :: AMQP.Basic.payload(),
  options :: Keyword.t()
) :: :ok | AMQP.Basic.error()

Publishes a message to an Exchange.

See AMQP.Basic.publish/5.

register_confirm_handler(channel, handler)

@callback register_confirm_handler(channel :: AMQP.Channel.t(), handler :: pid()) :: :ok

Register a handler for confirms on channel.

See AMQP.Confirm.register_handler/2.

register_return_handler(channel, handler)

@callback register_return_handler(channel :: AMQP.Channel.t(), handler :: pid()) :: :ok

Registers a handler to deal with returned messages.

See AMQP.Basic.return/2.

set_channel_options(channel, options)

@callback set_channel_options(channel :: AMQP.Channel.t(), options :: keyword()) ::
  :ok | {:error, any()}

Sets the message prefetch count or prefetch size.

See AMQP.Basic.qos/2.