View Source Lapin.Producer behaviour (lapin v2.0.0)

Extensible behaviour to define producer configuration.

Lapin provides a number of submodules which implement the patterns found in the RabbitMQ Tutorials.

defmodule ExampleApp.SomePatter do
  use Lapin.Producer

  [... callbacks implementation ...]
end

Summary

Types

Producer configuration

t()

Lapin Producer

Callbacks

Request publisher confirms (RabbitMQ only)

Declare exchange

Request message mandatory routing when publishing

Request message persistence when publishing

Functions

Wait for publish confirmation

Creates a producer from configuration

Find consumer by consumer_tag

Types

@type config() :: Keyword.t()

Producer configuration

The following keys are supported:

If using the Lapin.Producer.Config default implementation, the following keys are also supported:

  • exchange: exchange used for publish (String.t, required)
  • confirm: expect RabbitMQ publish confirms (boolean(), default: false)
  • mandatory: messages published as mandatory by default (boolean(), default: false)
  • persistent: messages published as persistent by default (boolean(), default: false)
@type t() :: %Lapin.Producer{
  channel: AMQP.Channel.t(),
  config: config(),
  exchange: String.t(),
  pattern: atom()
}

Lapin Producer

Callbacks

@callback confirm(producer :: t()) :: boolean()

Request publisher confirms (RabbitMQ only)

@callback exchange(producer :: t()) :: Lapin.Exchange.t()

Declare exchange

@callback mandatory(producer :: t()) :: boolean()

Request message mandatory routing when publishing

@callback persistent(producer :: t()) :: boolean()

Request message persistence when publishing

Functions

@spec confirm(t()) :: boolean()

Wait for publish confirmation

Link to this function

create(connection, config)

View Source
@spec create(AMQP.Connection.t(), config()) :: t()

Creates a producer from configuration

Link to this function

get(producers, exchange)

View Source
@spec get([t()], String.t()) :: {:ok, t()} | {:error, :not_found}

Find consumer by consumer_tag

Link to this function

publish(map, exchange, routing_key, payload, options)

View Source
@spec publish(
  t(),
  Lapin.Exchange.name(),
  Lapin.Exchange.routing_key(),
  Lapin.Message.payload(),
  Keyword.t()
) :: :ok | {:error, term()}

Publish message