AmqpDirector (amqp_director v1.6.0) View Source

Documentation for AmqpDirector.

This module provides wrapping for the Erlang code and is intended to be used with Elixir applications.

Link to this section Summary

Types

AMQP RPC Client configuraion options.

RabbitMQ broker connection options.

The content type of the AMQP message payload.

The handler function type for the AMQP RPC Server. The handler can be either arity 3 or 1. If the handler is of arity 3 then amqp_director will deconstruct the message and only provide the payload along with content type into the handler. If the handler is of arity 1 then it will be called with a raw AMQP message record

The type that a AMQP RPC Server handler function must return.

AMQP RPC Pull Client configuraion options.

Queue definition instructions.

AMQP RPC Server configuration options.

Functions

Creates a child specification for an AMQP RPC client.

Declares an exchange on the AMQP Broker.

Creates a child specification for an AMQP RPC pull client.

Binds a queue to an exchange.

Declares a queue on the AMQP Broker.

Creates a child specification for an AMQP RPC server.

Link to this section Types

Specs

client_option() ::
  {:app_id, String.t()}
  | {:queue_definitions, [queue_definition()]}
  | {:reply_queue, String.t()}
  | {:no_ack, boolean()}
  | :rabbitmq_direct_reply

AMQP RPC Client configuraion options.

  • :app_id - Specifies the identitifier of the client.
  • :queue_definition - A list of instructions for setting up the queues and exchanges. The RPC Client will call these during its initialization. The instructions should be created using exchange_declare/2, queue_declare/2 and queue_bind/3. E.g.
      {:queue_definitions, [
        AmqpDirector.exchange_declare("my_exchange", type: "topic"),
        AmqpDirector.queue_declare("my_queue", exclusive: true),
        AmqpDirector.queue_bind("my_queue", "my_exchange", "some.topic.*")
      ]}
  • :reply_queue - Allows naming for the reply queue. Defaults to empty name, making the RabbitMQ broker auto-generate the name.
  • :no_ack - Specifies if the client should NOT auto-acknowledge replies. Defaults to false.
  • :rabbitmq_direct_reply - use pseudo-queue amq.rabbitmq.reply-to instead of setting up a new queue to consume from. Only applicable when connecting to a rabbitmq server. By default not present.

Specs

connection_option() ::
  {:host, String.t()}
  | {:port, non_neg_integer()}
  | {:username, String.t()}
  | {:password, String.t()}
  | {:virtual_host, String.t()}

RabbitMQ broker connection options.

Specs

content_type() :: String.t()

The content type of the AMQP message payload.

Specs

handler() ::
  (payload :: binary(), content_type(), type :: String.t() ->
     handler_return_type())
  | (raw_msg ::
       {basic_deliver :: AmqpDirector.Definitions.basic_deliver(),
        amqp_msg :: AmqpDirector.Definitions.amqp_msg()} ->
       handler_return_type())

The handler function type for the AMQP RPC Server. The handler can be either arity 3 or 1. If the handler is of arity 3 then amqp_director will deconstruct the message and only provide the payload along with content type into the handler. If the handler is of arity 1 then it will be called with a raw AMQP message record

Specs

handler_return_type() ::
  {:reply,
   payload :: binary() | {binary(), AmqpDirector.Definitions.amqp_table()},
   content_type()}
  | :reject
  | :reject_no_requeue
  | {:reject_dump_msg, String.t()}
  | :ack

The type that a AMQP RPC Server handler function must return.

Specs

pull_client_option() ::
  {:app_id, String.t()} | {:queue_definitions, [queue_definition()]}

AMQP RPC Pull Client configuraion options.

  • :app_id - Specifies the identitifier of the client.
  • :queue_definition - A list of instructions for setting up the queues and exchanges. The RPC Client will call these during its initialization. The instructions should be created using exchange_declare/2, queue_declare/2 and queue_bind/3. E.g.
      {:queue_definitions, [
        AmqpDirector.exchange_declare("my_exchange", type: "topic"),
        AmqpDirector.queue_declare("my_queue", exclusive: true),
        AmqpDirector.queue_bind("my_queue", "my_exchange", "some.topic.*")
      ]}

Specs

queue_definition() :: exchange_declare() | queue_declare() | queue_bind()

Queue definition instructions.

Specs

server_option() ::
  {:consume_queue, String.t()}
  | {:consumer_tag, String.t()}
  | {:queue_definitions, [queue_definition()]}
  | {:no_ack, boolean()}
  | {:qos, number()}
  | {:reply_persistent, boolean()}

AMQP RPC Server configuration options.

  • :consume_queue - Specifies the name of the queue on which the server will consume messages.
  • :consumer_tag - Specifies the tag that the server will be identified when listening on the queue.
  • :queue_definition - A list of instructions for setting up the queues and exchanges. The RPC Server will call these during its initialization. The instructions should be created using exchange_declare/2, queue_declare/2 and queue_bind/3. E.g.
        {:queue_definitions, [
          AmqpDirector.exchange_declare("my_exchange", type: "topic"),
          AmqpDirector.queue_declare("my_queue", exclusive: true),
          AmqpDirector.queue_bind("my_queue", "my_exchange", "some.topic.*")
        ]}
  • :no_ack - Specifies if the server should NOT auto-acknowledge consumed messages. Defaults to false.
  • :qos - Specifies the prefetch count on the consume queue. Defaults to 2.
  • :reply_persistent - Specifies the delivery mode for the AMQP replies. Setting this to true will make the broker log the messages on disk. See AMQP specification for more information. Defaults to false

Link to this section Functions

Link to this function

client_child_spec(name, connectionInfo, config)

View Source

Specs

client_child_spec(atom(), [connection_option()], [client_option()]) ::
  Supervisor.child_spec()

Creates a child specification for an AMQP RPC client.

This specification allows for RPC clients to be nested under any supervisor in the application using AmqpDirector. The RPC client can perform queue initialization. It will also create a reply queue to consume replies on. The client can then be used using AmqpDirector.Client module API. See client_option/0 for configuration options.

The client handles reconnecting by itself.

Link to this function

exchange_declare(name, params \\ [])

View Source

Specs

exchange_declare(String.t(), Keyword.t()) :: exchange_declare()

Declares an exchange on the AMQP Broker.

This function is intended to be using within :queue_definitions configuration parameter of a client or a server. See client_option/0 or server_option/0 for details.

Available options are: :passive, :durable, :auto_delete, :internal and :arguments. See AMQP specification for details on exchange declaration.

Link to this function

pull_client_child_spec(name, connectionInfo, config)

View Source

Specs

pull_client_child_spec(atom(), [connection_option()], [pull_client_option()]) ::
  Supervisor.child_spec()

Creates a child specification for an AMQP RPC pull client.

This specification allows for RPC clients to be nested under any supervisor in the application using AmqpDirector. The pull client uses the Synchronous Pull (#basic.get{}) over AMQP. The client can then be used using AmqpDirector.PullClient module API. See pull_client_option/0 for configuration options.

The client handles reconnecting by itself.

Link to this function

queue_bind(name, exchange, routing_key)

View Source

Specs

queue_bind(String.t(), String.t(), String.t()) :: queue_bind()

Binds a queue to an exchange.

This function is intended to be using within :queue_definitions configuration parameter of a client or a server. See client_option/0 or server_option/0 for details. See AMQP specification for details of queue binding.

Link to this function

queue_declare(name, params \\ [])

View Source

Specs

queue_declare(String.t(), Keyword.t()) :: queue_declare()

Declares a queue on the AMQP Broker.

This function is intended to be using within :queue_definitions configuration parameter of a client or a server. See client_option/0 or server_option/0 for details.

Available options are: :passive, :durable, :exclusive, :auto_delete and :arguments. See AMQP specification for details on queue declaration.

Link to this function

server_child_spec(name, handler, connectionInfo, count, config)

View Source

Specs

Creates a child specification for an AMQP RPC server.

This specification allows for RPC servers to be nested under any supervisor in the application using AmqpDirector. The RPC Server will initialize the queues it is instructed to and will then consume messages on the queue specified. The handler function will be called to handle each request. See server_option/0 for configuration options and handler/0 for the type spec of the handler function.

The server handles reconnecting by itself.