Class Connection

This represents a single connection to a RabbitMQ server (or cluster). Once created, it will immediately attempt to establish a connection. When the connection is lost, for whatever reason, it will reconnect. This implements the EventEmitter interface and may emit error events. Close it with Connection#close()

Example

const rabbit = new Connection('amqp://guest:guest@localhost:5672')
rabbit.on('error', (err) => {
console.log('RabbitMQ connection error', err)
})
rabbit.on('connection', () => {
console.log('RabbitMQ (re)connected')
})
process.on('SIGINT', () => {
rabbit.close()
})

Hierarchy

  • EventEmitter
    • Connection

Constructors

Methods

  • Allocate and return a new AMQP Channel. You MUST close the channel yourself. Will wait for connect/reconnect when necessary.

    Returns Promise<Channel>

  • Wait for channels to close and then end the connection. Will not automatically close any channels, giving you the chance to ack/nack any outstanding messages while preventing new channels.

    Returns Promise<void>

  • Create a message publisher that can recover from dropped connections. This will create a dedicated Channel, declare queues, declare exchanges, and declare bindings. If the connection is reset, then all of this setup will rerun on a new Channel. This also supports retries.

    Parameters

    Returns Publisher

  • This will create a single "client" Channel on which you may publish messages and listen for direct responses. This can allow, for example, two micro-services to communicate with each other using RabbitMQ as the middleman instead of directly via HTTP.

    Parameters

    Returns RPCClient

  • The connection is successfully (re)established

    Parameters

    • name: "connection"
    • cb: (() => void)
        • (): void
        • Returns void

    Returns Connection

  • The rabbitmq server is low on resources. Message publishers should pause. The outbound side of the TCP socket is blocked until "connection.unblocked" is received, meaning messages will be held in memory. https://www.rabbitmq.com/connection-blocked.html

    Parameters

    • name: "connection.blocked"
    • cb: ((reason) => void)
        • (reason): void
        • Parameters

          • reason: string

          Returns void

    Returns Connection

  • The rabbitmq server is accepting new messages.

    Parameters

    • name: "connection.unblocked"
    • cb: (() => void)
        • (): void
        • Returns void

    Returns Connection

  • Parameters

    • name: "error"
    • cb: ((err) => void)
        • (err): void
        • Parameters

          • err: any

          Returns void

    Returns Connection

  • Immediately destroy the connection. All channels are closed. All pending actions are rejected.

    Returns void

Generated using TypeDoc