Rabbit v0.1.0 Rabbit.Producer behaviour View Source

A RabbitMQ producer process.

This wraps around the standard AMQP.Channel. It provides the following benefits:

  • Durability during connection and channel failures through use of expotential backoff.
  • Channel pooling for increased publishing performance.
  • Ability to create module-based producers that permit easy runtime setup through an init/1 callback.
  • Simplification of standard publishing options.
  • Automatic payload encoding based on available serializers and message content type.

Example

# This is a connection
defmodule MyConnection do
  use Rabbit.Connection
end

# This is a producer
defmodule MyProducer do
  use Rabbit.Producer

  # Callbacks

  def init(opts) do
    # Perform any runtime configuration...
    {:ok, opts}
  end
end

# Start the connection
MyConnection.start_link()

# Start the producer
MyProducer.start_link(MyConnection, publish_opts: [content_type: "application/json"])

# Publish a message
MyProducer.publish("my_exchange", "my_queue", %{foo: "bar"})

Serializers

When a message is published, its content type is compared to the list of available serializers. If a serializer matches the content type, the message will be automatically encoded.

You can find out more about serializers at Rabbit.Serializer.

Link to this section Summary

Link to this section Types

Link to this type

exchange() View Source
exchange() :: String.t()

Link to this type

message() View Source
message() :: term()

Link to this type

publish_option() View Source
publish_option() ::
  {:mandatory, boolean()}
  | {:immediate, boolean()}
  | {:content_type, String.t()}
  | {:content_encoding, String.t()}
  | {:headers, [{String.t(), String.t()}]}
  | {:persistent, boolean()}
  | {:correlation_id, String.t()}
  | {:priority, 1..9}
  | {:reply_to, String.t()}
  | {:expiration, non_neg_integer()}
  | {:message_id, String.t()}
  | {:timestamp, non_neg_integer()}
  | {:type, String.t()}
  | {:user_id, String.t()}
  | {:app_id, String.t()}

Link to this type

publish_options() View Source
publish_options() :: [publish_option()]

Link to this type

routing_key() View Source
routing_key() :: String.t()

Link to this type

start_option() View Source
start_option() ::
  {:pool_size, non_neg_integer()}
  | {:max_overflow, non_neg_integer()}
  | {:publish_opts, publish_options()}

Link to this type

start_options() View Source
start_options() :: [start_option()]

Link to this section Callbacks

Link to this callback

init(start_options) View Source (optional)
init(start_options()) :: {:ok, start_options()} | :ignore

Link to this callback

publish(exchange, routing_key, message, publish_options, timeout) View Source

Starts a RabbitMQ producer process.

Options

  • :immediate - tocome..

Stops a RabbitMQ producer process.