AMQPHelpers.Reliability.Producer (AMQP Helpers v1.3.0)

A producer for dealing with reliability scenarios.

A AMQPHelpers.Reliability.Producer is process which manages a reliable send operation over AMQP, where messages are acknowledge by the broker after sending them. Publisher Confirms AMQP extension is used to achieve this.

Example

This Producer enforces the usage of AMQP.Application, so after defining our application connection and channel we can start a producer and start publishing message in a reliable way.

alias AMQPHelpers.Reliability.Producer

{:ok, producer} = Consumer.start_link(channel_name: :my_channel_name)

Producer.publish(producer, "exchange", "routing_key", "payload", message_id: "foo")

Link to this section Summary

Types

Option values used by start_link/1 function.

Options used by start_link/1 function.

Functions

Returns a specification to start this module under a supervisor.

Publish a message ensuring that the broker receives it.

Setups the channel for reliable message delivery.

Starts a Producer process linked to the current process.

Link to this section Types

Specs

option() ::
  GenServer.option()
  | {:adapter, module()}
  | {:setup_channel_on_init, boolean()}
  | {:channel, AMQP.Channel.t()}
  | {:channel_name, binary() | atom()}
  | {:retry_interval, non_neg_integer()}

Option values used by start_link/1 function.

Specs

options() :: [option()]

Options used by start_link/1 function.

Link to this section Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

publish(server, exchange, routing_key, payload, opts, timeout \\ 5000)

Specs

Publish a message ensuring that the broker receives it.

Similar to AMQPHelpers.Adapter.publish/5 but ensures that the broker receives the message sent. Some message delivery options are enabled by default (mandatory and persistent) and message_id option is required to track the message state.

Link to this function

setup_channel(producer)

Specs

setup_channel(GenServer.server()) :: :ok

Setups the channel for reliable message delivery.

This function is used to setup reliable message delivery when setup_channel_on_init is set to false. Not required by default but useful for testing purposes.

Link to this function

start_link(opts \\ [])

Specs

start_link(options()) :: GenServer.on_start()

Starts a Producer process linked to the current process.

Options

The following option can be given to Producer when starting it. Note that queue_name is required.

  • adapter - Sets the AMQPHelpers.Adapter. Defaults to AMQPHelpers.Adapters.AMQP.
  • setup_channel_on_init - Whether to configure the channel for reliable message sending on init or not. Defaults to false.
  • channel - The channel to use to consume messages. NOTE: do not use this for production environments because this producer does not supervise the given channel. Instead, use channel_name which makes use of AMQP.Application.
  • channel_name - The name of the configured channel to use. See AMQP.Application for more information. Defaults to :default.
  • retry_interval - The number of millisecond to wait if an error happens when trying to consume messages or when trying to open a channel.

GenServer.options/0 are also available. See GenServer.start_link/2 for more information about these.