RabbitMQPoolEx

Build StatusHex.pmDocumentation

rabbitmq_pool_ex is an Elixir library that provides a robust and efficient connection pooling mechanism for RabbitMQ. It leverages poolboy to manage a pool of connections, ensuring high performance and reliability in message-driven applications.

Features

Installation

To integrate rabbitmq_pool_ex into your project, add the following to your mix.exs dependencies:

defp deps do
  [
    {:rabbitmq_pool_ex, "~> 1.0.0"}
  ]
end

Then, fetch and install the dependencies by running:

mix deps.get

Getting started

To use rabbitmq_pool_ex, add the following to your application's supervision tree:

defmodule MyApp.Application do
  @moduledoc false

  @impl true
  def start(_type, _args) do
    children = [
      {RabbitMQPoolEx.PoolSupervisor, get_pool_config()}
    ]

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

  defp get_pool_config do
    [
      rabbitmq_config: [host: "localhost", port: 5672],
      connection_pools: [
        [
          name: {:local, :default_pool},
          size: 5,
          channels: 20,
          reuse_channels?: true,
          max_overflow: 2
        ]
      ]
    ]
  end
end

and start interaction with RabbitMQ:

RabbitMQPoolEx.with_channel(:rabbitmq_pool, fn
  {:ok, channel} ->
    AMQP.Basic.publish(channel, "exchange_name", "routing_key", "Hello, World!")
    :ok
  {:error, reason} ->
    IO.puts("Failed to acquire channel", error: inspect(reason))
end)

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request with improvements or bug fixes.

Running Tests

To run tests locally:

make up

mix test

License

rabbitmq_pool_ex is released under the Apache 2.0 License.