Skip to content

amqpx v1.0.1


amqpx / index / Connection

Interface: Connection ​

Defined in: src/connection/connection.ts:75

Extends ​

  • EventEmitter<ConnectionEventMap>

Methods ​

close() ​

close(timeout?): Promise<void>

Defined in: src/connection/connection.ts:95

Gracefully closes the connection. Emits the close event after the underlying amqplib connection is fully shut down. Has no effect if the connection is in preconnect or closed state.

Parameters ​

ParameterTypeDescription
timeout?numberMaximum milliseconds to wait for the underlying connection to close. Throws 'Connection close timed out' if exceeded. Waits 30s when omitted.

Returns ​

Promise<void>


connect() ​

connect(): Promise<Connection>

Defined in: src/connection/connection.ts:81

Establishes the connection. Safe to call concurrently — multiple callers will share the same attempt. After retries are exhausted (ConnectionEventMap.connectionRetryExhausted), the connection moves to the closed state, but connect() may be called again to start a fresh connection attempt.

Returns ​

Promise<Connection>


createBatchConsumerForExchange() ​

createBatchConsumerForExchange<T>(exchange, options, queueOptions?): Promise<BatchConsumer<T, Record<string, unknown>>>

Defined in: src/connection/connection.ts:144

Creates a batch consumer for an exchange and opens a dedicated channel for it. Internally asserts an exclusive queue and binds it to the exchange.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
exchangeExchangeSource exchange.
optionsExchangeBatchConsumerOptions<T>Batch consumer options, including the binding pattern.
queueOptions?ExchangeConsumerQueueOptionsOptions for the auto-created exclusive queue.

Returns ​

Promise<BatchConsumer<T, Record<string, unknown>>>


createBatchConsumerForQueue() ​

createBatchConsumerForQueue<T>(queue, options?): Promise<BatchConsumer<T, Record<string, unknown>>>

Defined in: src/connection/connection.ts:136

Creates a batch consumer for a queue and opens a dedicated channel for it.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
queueQueueSource queue.
options?BatchConsumerOptions<T>Optional batch consumer options (batch size, failure strategy, prefetch, …).

Returns ​

Promise<BatchConsumer<T, Record<string, unknown>>>


createChannel() ​

createChannel(isConfirmed?): Channel

Defined in: src/connection/connection.ts:101

Creates a new channel on this connection.

Parameters ​

ParameterTypeDescription
isConfirmed?booleanIf true, creates a confirm channel (publisher confirms enabled).

Returns ​

Channel


createConsumerForExchange() ​

createConsumerForExchange<T>(exchange, options, queueOptions?): Promise<Consumer<T, Record<string, unknown>>>

Defined in: src/connection/connection.ts:130

Creates a consumer for an exchange and opens a dedicated channel for it. Internally asserts an exclusive queue and binds it to the exchange.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
exchangeExchangeSource exchange.
optionsExchangeConsumerOptions<T>Consumer options, including the binding pattern.
queueOptions?ExchangeConsumerQueueOptionsOptions for the auto-created exclusive queue.

Returns ​

Promise<Consumer<T, Record<string, unknown>>>


createConsumerForQueue() ​

createConsumerForQueue<T>(queue, options?): Promise<Consumer<T, Record<string, unknown>>>

Defined in: src/connection/connection.ts:122

Creates a consumer for a queue and opens a dedicated channel for it.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
queueQueueSource queue.
options?ConsumerOptions<T>Optional consumer options (failure strategy, prefetch, …).

Returns ​

Promise<Consumer<T, Record<string, unknown>>>


createProducerForExchange() ​

createProducerForExchange<T>(exchange, options?, isConfirmed?): Promise<Producer<T, T>>

Defined in: src/connection/connection.ts:116

Creates a producer for an exchange and opens a dedicated channel for it.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
exchangeExchangeTarget exchange.
options?ProducerOptions<T>Optional producer options (serialization, routing key, hooks, …).
isConfirmed?booleanIf true, the dedicated channel uses publisher confirms.

Returns ​

Promise<Producer<T, T>>


createProducerForQueue() ​

createProducerForQueue<T>(queue, options?, isConfirmed?): Promise<Producer<T, T>>

Defined in: src/connection/connection.ts:109

Creates a producer for a queue and opens a dedicated channel for it.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
queueQueueTarget queue.
options?ProducerOptions<T>Optional producer options (serialization, routing key, hooks, …).
isConfirmed?booleanIf true, the dedicated channel uses publisher confirms.

Returns ​

Promise<Producer<T, T>>


native() ​

native(): Promise<ChannelModel>

Defined in: src/connection/connection.ts:150

Returns the underlying amqplib connection. Resolves once the connection is established. This is intended for internal use.

Returns ​

Promise<ChannelModel>


state() ​

state(): ConnectionState

Defined in: src/connection/connection.ts:86

Returns the current state of the connection.

Returns ​

ConnectionState

Released under the MIT License.