Flux AMQP v0.0.5 FluxAMQP View Source

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

Link to this section Summary

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, :failed_to_close_connection}

Closes an open Connection.

Parameters

Examples

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

close_connection!(connection)

View Source (since 0.0.5)
close_connection!(AMQP.Connection.t()) :: :ok

Closes an open Connection.

Similar to close_connection/1, but raises FluxAMQP.Error.t/0 on failure.

Examples

iex> 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.Connection.t() | AMQP.Channel.t()} | {:error, :failed_to_connect}

Open a AMQP.Connection.t/0 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. Additionally, if the option :only_connect? is true, this function will not configure channel and will return a AMQP.Connection.t/0, otherwise will configure a AMQP.Channel.t/0 and will return it. 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

connect!(consumer, opts \\ [])

View Source (since 0.0.5)

Open a AMQP.Connection.t/0 and configure it.

Similar to connect/2, but raises FluxAMQP.Error.t/0 on failure.

Examples

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

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

open_channel(connection)

View Source (since 0.0.5)
open_channel(AMQP.Connection.t()) ::
  {:ok, AMQP.Channel.t()} | {:error, :failed_to_open_channel}

Open a AMQP.Channel.t/0 based on AMQP.Connection.t/0.

Parameters

Examples

iex> connection = FluxAMQP.connect!(MODULE, only_connect?: true) ...> result = FluxAMQP.open_channel(connection) ...> with {:ok, %AMQP.Channel{}} <- result, do: :passed :passed

Link to this function

open_channel!(connection)

View Source (since 0.0.5)
open_channel!(AMQP.Connection.t()) :: AMQP.Channel.t()

Open a AMQP.Channel.t/0 based on AMQP.Connection.t/0.

Similar to open_channel/1, but raises FluxAMQP.Error.t/0 on failure.

Examples

iex> connection = FluxAMQP.connect!(MODULE, only_connect?: true) ...> result = FluxAMQP.open_channel!(connection) ...> with %AMQP.Channel{} <- result, do: :passed :passed

Link to this function

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

View Source (since 0.0.1)

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.send("Hello, World!", "some.amqp.route")
: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.

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

Link to this function

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

View Source (since 0.0.5)

Send AMQP message.

Similar to send/3, but raises FluxAMQP.Error.t/0 on failure.

Examples

iex> FluxAMQP.send!("Hello, World!", "some.amqp.route")
:ok