rabbit_mq v0.0.9 RabbitMQ.Topology

A convenience module that can be used to establish the (RabbitMQ) routing topology.

First, create a module that uses RabbitMQ.Topology to define exchanges and their corresponding bindings as shown below.

⚠️ Please note that exclusive queues cannot be configured here. You may need to consult the RabbitMQ.Consumer module for details on how exclusive queues can be set up and used.

defmodule RabbitSample.Topology do
  use RabbitMQ.Topology,
    exchanges: [
      {"customer", :topic,
      [
        {"customer.created", "customer/customer.created", durable: true},
        {"customer.updated", "customer/customer.updated", durable: true}
      ], durable: true}
    ]
end

Then, simply add this module to your supervision tree, before any Consumers or Producers that rely on the exchanges configured within it start.

⚠️ Please note that the Topology module will terminate gracefully as soon as the desired routing is configured.

children = [
  RabbitSample.Topology,
  RabbitSample.CustomerProducer,
  RabbitSample.CustomerCreatedConsumer,
  RabbitSample.CustomerUpdatedConsumer
]

opts = [strategy: :one_for_one, name: RabbitSample.Supervisor]
Supervisor.start_link(children, opts)

Link to this section Summary

Functions

The macro to use this module.

Link to this section Functions

Link to this macro

__using__(opts)

(macro)

The macro to use this module.

Available options:

exchanges: [
  {
    # Exchange name
    "customer",
    # Exchange type, only topic is supported at the moment
    :topic,
    # List of bindings
    [
      {
        # Routing/binding key
        "#",
        # Queue name
        "customer/#",
        # Queue opts (optional)
        durable: true
      }
    ],
    # Exchange opts
    durable: true
  }
]