amqp_pool — Logtalk 3.100.1

category

# `amqp_pool`

AMQP connection pool category. Import this category into an object to create a named connection pool with automatic connection management.

Availability:
`logtalk_load(amqp(loader))`
Author: Paulo Moura
Version: 1:0:0
Date: 2026-02-19
Compilation flags:
`static`
Uses:
amqp
list
os
Remarks:
(none)
Inherited public predicates:
(none)

## Public predicates

### `initialize/1`

Initializes the connection pool with the given configuration options. Must be called before using other pool predicates.

Compilation flags:
`static`
Template:
`initialize(Options)`
Mode and number of proofs:
`initialize(+list)` - `one_or_error`
Remarks:

> - Option host(Host): AMQP server hostname. Default is localhost.

> - Option port(Port): AMQP server port. Default is 5672.

> - Option min_size(N): Minimum number of connections to maintain. Default is 1.

> - Option max_size(N): Maximum number of connections allowed. Default is 10.

> - Option connection_options(Options): Options passed to amqp::connect/4. Default is [].

### `destroy/0`

Destroys the pool, closing all connections and clearing state.

Compilation flags:
`static`
Mode and number of proofs:
`destroy` - `one`

### `acquire/1`

Acquires a connection from the pool. Returns an available connection or creates a new one if the pool is not at maximum capacity.

Compilation flags:
`static`
Template:
`acquire(Connection)`
Mode and number of proofs:
`acquire(--compound)` - `one_or_error`
Exceptions:
Pool not initialized:
`pool_error(not_initialized)`
Pool exhausted (at max capacity):
`pool_error(exhausted)`

### `release/1`

Releases a connection back to the pool, making it available for reuse.

Compilation flags:
`static`
Template:
`release(Connection)`
Mode and number of proofs:
`release(+compound)` - `one`

### `with_connection/1`

Acquires a connection, calls Goal with the connection as argument, and releases the connection. The connection is released even if Goal fails or throws an exception.

Compilation flags:
`static`
Template:
`with_connection(Goal)`
Meta-predicate template:
`with_connection(1)`
Mode and number of proofs:
`with_connection(+callable)` - `zero_or_more`

### `stats/1`

Returns pool statistics as a compound term stats(Available, InUse, Total, MinSize, MaxSize).

Compilation flags:
`static`
Template:
`stats(Stats)`
Mode and number of proofs:
`stats(-compound)` - `one`

### `resize/2`

Resizes the pool by setting new minimum and maximum sizes.

Compilation flags:
`static`
Template:
`resize(MinSize,MaxSize)`
Mode and number of proofs:
`resize(+integer,+integer)` - `one_or_error`

## Protected predicates

(no local declarations; see entity ancestors if any)

## Private predicates

### `pool_config/5`

Stores the pool configuration parameters.

Compilation flags:
`dynamic`
Template:
`pool_config(Host,Port,MinSize,MaxSize,ConnectionOptions)`
Mode and number of proofs:
`pool_config(?atom,?integer,?integer,?integer,?list)` - `zero_or_one`

### `available/1`

Tracks connections that are available for use.

Compilation flags:
`dynamic`
Template:
`available(Connection)`
Mode and number of proofs:
`available(?compound)` - `zero_or_more`

### `in_use/2`

Tracks connections currently in use along with their acquisition timestamp.

Compilation flags:
`dynamic`
Template:
`in_use(Connection,AcquireTimestamp)`
Mode and number of proofs:
`in_use(?compound,?compound)` - `zero_or_more`

## Operators

(none)