Flux AMQP v0.0.3 FluxAMQP View Source

An interface to connect to AMQP broker, sending and retrieving messages.

Link to this section Summary

Functions

Closes an open Connection.

Open a Connection and configure it.

Link to this section Functions

Link to this function

close_connection(connection)

View Source (since 0.0.1)
close_connection(AMQP.Connection.t()) :: :ok | {:error, atom()}

Closes an open Connection.

Parameters

Examples

iex> {:ok, connection} = FluxAMQP.connect(__MODULE__, only_connect?: true)
...> FluxAMQP.close_connection(connection)
:ok
Link to this function

connect(consumer, opts \\ [])

View Source (since 0.0.1)
connect(module(), keyword()) ::
  {:ok, AMQP.Channel.t()} | {:ok, AMQP.Connection.t()} | {:error, atom()}

Open a Connection and configure it.

Parameters

  • consumer - The module which will consume AMQP messages. Accepts module/0.

  • opts - Keyword list with connection settings. Definition is the same as application configuration and the opts defined here are merged with the application configuration. Can be blank. Accepts keyword/0.

Examples

iex> result = FluxAMQP.connect(__MODULE__, only_connect?: true)
...> with {:ok, %AMQP.Connection{}} <- result, do: :passed
:passed

iex> result = FluxAMQP.connect(__MODULE__)
...> with {:ok, %AMQP.Channel{}} <- result, do: :passed
:passed
Link to this function

send(payload, routing_key, opts \\ [])

View Source (since 0.0.1)
send(String.t(), String.t(), keyword()) :: :ok | {:error, atom()}

Send AMQP message.

Parameters

  • payload - The message. Accepts String.t/0.

  • routing_key - The AMQP routing key which the message will be sent. Accepts String.t/0.

  • opts - Keyword list with options. Can be blank. Accepts keyword/0.

Examples

iex> FluxAMQP.Sender.send(
...>  "Hello, World!",
...>  "some.amqp.route",
...>  broker_uri: "amqp://guest:guest@rabbitmq",
...>  close_connection?: true,
...>  declare_exchange?: true,
...>  reconnection: [maximum_attempts: 3, waiting_ms: 5_000]
...>)
:ok

Options

  • :broker - Keyword list with broker connection settings. Definition is the same as application configuration and the opts defined here are merged with the broker application configuration. Accepts keyword/0.

  • :channel - A valid AMQP.Channel.t/0 struct. If not set, a new channel will be created.

  • :close_connection? - If true, it will close the connection. Defaults to true. Accepts boolean/0.

  • :connection - A valid AMQP.Connection.t/0 struct. If not set, a new connection will be created.

  • :declare_exchange? - If true, it will declare the AMQP exchange into channel. Defaults to true. Accepts boolean/0.

  • :exchange - A string with valid AMQP.Exchange.declare/4 definition. If not set, amq.topic will be used. Accepts String.t/0.

  • :publish_options - A Keyword list with valid AMQP.Basic.publish/5 options. Defaults to an empty list. Accepts keyword/0.