AMQPChannelPool (amqp_channel_pool v0.1.0)

A library for managing an AMQP channel pool with NimblePool.

This module provides an abstraction over NimblePool to simplify working with AMQP connections and channels. It includes functions for starting the pool, checking out channels, and stopping the pool.

Summary

Functions

Checks out an AMQP channel from the pool and executes the given function.

Defines the child specification for the pool.

Starts the AMQP channel pool.

Stops the AMQP channel pool.

Functions

Checks out an AMQP channel from the pool and executes the given function.

Arguments

  • fun - A function that receives the checked-out channel and performs operations on it. The function must return the result of the operation.

Examples

AMQPChannelPool.checkout!(fn channel ->
  AMQP.Basic.publish(channel, "exchange_name", "routing_key", "message")
end)

Returns

The result of the provided function.

Link to this function

child_spec(opts)

Defines the child specification for the pool.

This function allows the module to be used directly as a child in a supervision tree.

Arguments

  • opts - A keyword list containing the options for starting the pool.

Returns

A map defining the child specification.

Examples

children = [
  {AMQPChannelPool, opts: %{host: "localhost"}, pool_size: 5}
]
Supervisor.start_link(children, strategy: :one_for_one)
Link to this function

start_link(opts)

Starts the AMQP channel pool.

Arguments

  • opts - A keyword list containing:
    • :opts - A map of options for the AMQP connection.
    • :pool_size - The number of workers in the pool (default: 10).

Examples

{:ok, _pid} = AMQPChannelPool.start_link(opts: [host: "localhost"], pool_size: 5)

Returns

  • on success.
  • on failure.

Stops the AMQP channel pool.

This function shuts down the supervisor managing the pool, ensuring all resources are released properly.

Examples

:ok = AMQPChannelPool.stop()