AmqpDirector.Client (amqp_director v1.6.0) View Source

The AMQP RPC Client.

This module contains functionality for an RPC client. See AmqpDirector.client_child_spec/3 for details on how to start the RPC client.

Link to this section Summary

Types

Error types for the synchronous RPC call.

Options for an RPC request.

Link to this section Types

Specs

call_error_reason() :: :no_route | :no_consumers | {:reply_code, number()}

Error types for the synchronous RPC call.

Specs

request_options() ::
  {:timeout, pos_integer() | :infinity}
  | {:persistent, boolean()}
  | {:ttl, pos_integer()}
  | {:return_headers, boolean()}

Options for an RPC request.

  • :ttl - Specified the TTL of the message on AMQP.
  • :timeout - Time the client awaits response. Only valid for call/6. This is the gen_server timeout. Should be larger than the value for :ttl
  • :persistent - Specifies the delivery mode for the AMQP messages. Setting this to true will make the broker log the messages on disk. See AMQP specification for more information. Defaults to false
  • :return_headers - Specified if the caller is interested into the amqp message header table

Link to this section Functions

Link to this function

await(client, timeout \\ :infinity)

View Source

Specs

await(client :: atom() | pid(), timeout :: pos_integer() | :infinity) :: any()

Await until the client is started.

This will block the caller for the specified time or until the RPC client starts. This can be use to ensure that the client is running before requests are made.

Link to this function

call(client, exchange, routing_key, payload, content_type, options \\ [timeout: 5000])

View Source

Specs

call(
  client :: atom() | pid(),
  exchange :: String.t(),
  routing_key :: String.t(),
  payload :: binary() | {binary(), AmqpDirector.Definitions.amqp_table()},
  content_type :: String.t(),
  options :: [request_options()]
) ::
  {:ok, content :: binary() | {binary(), AmqpDirector.Definitions.amqp_table()},
   content_type :: String.t()}
  | {:error, call_error_reason()}

Send a synchronous request.

Sends a synchronous request to an AMQP broker and awaits for response for the length of :timeout option (Defaults to 5 seconds). It sends the message to the specified exchange with the specified routing key. The content_type specifies the type of the payload. AMQP message type is always set to "request" in case of a call.

Link to this function

cast(client, exchange, routing_key, payload, content_type, type, options \\ [])

View Source

Specs

cast(
  client :: atom() | pid(),
  exchange :: String.t(),
  routing_key :: String.t(),
  payload :: binary() | {binary(), AmqpDirector.Definitions.amqp_table()},
  content_type :: String.t(),
  type :: String.t(),
  options :: [request_options()]
) :: :ok

Send an asynchronous request.

Sends an asynchronous request to an AMQP broker without expecting any response. It is send to the specified exchange using the specified routing key. The content_type specifies the type of the payload while the type parameters refers to the AMQP message type header. See the AMQP reference for details.