Skip to content

amqpx v1.0.1


amqpx / index / ConnectionImplementation

Class: ConnectionImplementation

Defined in: src/connection/connection-implementation.ts:18

Extends

  • EventEmitter<ConnectionEventMap>

Implements

Constructors

Constructor

new ConnectionImplementation(options, retryStrategy?, socketOptions?): ConnectionImplementation

Defined in: src/connection/connection-implementation.ts:24

Parameters

ParameterType
optionsConnect
retryStrategyRetryStrategy
socketOptions?unknown

Returns

ConnectionImplementation

Overrides

EventEmitter<ConnectionEventMap>.constructor

Methods

close()

close(timeout?): Promise<void>

Defined in: src/connection/connection-implementation.ts:98

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

ParameterTypeDefault valueDescription
timeoutnumber30_000Maximum milliseconds to wait for the underlying connection to close. Throws 'Connection close timed out' if exceeded. Waits 30s when omitted.

Returns

Promise<void>

Implementation of

Connection.close


connect()

connect(): Promise<ConnectionImplementation>

Defined in: src/connection/connection-implementation.ts:36

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<ConnectionImplementation>

Implementation of

Connection.connect


createBatchConsumerForExchange()

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

Defined in: src/connection/connection-implementation.ts:160

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>>>

Implementation of

Connection.createBatchConsumerForExchange


createBatchConsumerForQueue()

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

Defined in: src/connection/connection-implementation.ts:156

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>>>

Implementation of

Connection.createBatchConsumerForQueue


createChannel()

createChannel(isConfirmed?): Channel

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

Creates a new channel on this connection.

Parameters

ParameterTypeDefault valueDescription
isConfirmedbooleanfalseIf true, creates a confirm channel (publisher confirms enabled).

Returns

Channel

Implementation of

Connection.createChannel


createConsumerForExchange()

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

Defined in: src/connection/connection-implementation.ts:148

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>>>

Implementation of

Connection.createConsumerForExchange


createConsumerForQueue()

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

Defined in: src/connection/connection-implementation.ts:152

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>>>

Implementation of

Connection.createConsumerForQueue


createProducerForExchange()

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

Defined in: src/connection/connection-implementation.ts:164

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>>

Implementation of

Connection.createProducerForExchange


createProducerForQueue()

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

Defined in: src/connection/connection-implementation.ts:168

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>>

Implementation of

Connection.createProducerForQueue


native()

native(): Promise<ChannelModel>

Defined in: src/connection/connection-implementation.ts:134

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

Returns

Promise<ChannelModel>

Implementation of

Connection.native


state()

state(): ConnectionState

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

Returns the current state of the connection.

Returns

ConnectionState

Implementation of

Connection.state

Released under the MIT License.