Classdesc

An instance of a connection to a RabbitMQ server

Hierarchy

  • Connection

Constructors

Accessors

  • get active(): boolean
  • Whether the connection is active or not.

    Returns boolean

    Since

    1.0.9

    Remarks

    If the connection is not active, it will not be possible to create new channels, meaning that it will not be possible to create new queues, publish messages, consume messages or acknowledge messages.

    We use this flag to prevent operations that require an active connection from being executed in both the Connection and Queue classes.

  • get activeConnectionTimeout(): number
  • The amount of time to wait for the connection to become active or indicate closed / blocked before throwing an exception.

    Returns number

    Since

    1.0.9

    Remarks

    This value is used internally by the Connection class to determine how long to wait for the connection to become active or indicate closed / blocked before throwing an exception but can be set by the user by calling Connection.setActiveConnectionTimeout if they want to change the default value.

Methods

  • Removes the specified event listener for the 'connected' event.

    Parameters

    • event: "connected"

      The name of the event to remove the listener from.

    • listener: ConnectionEventListener

      The function to be removed from the event listeners.

    Returns void

    void

  • Removes the specified event listener for the 'error' event.

    Parameters

    • event: "error"

      The name of the event to remove the listener from.

    • listener: ConnectionErrorEventListener

      The function to be removed from the event listeners.

    Returns void

    void

  • Removes the specified event listener for the 'close' event.

    Parameters

    • event: "close"

      The name of the event to remove the listener from.

    • listener: ConnectionCloseEventListener

      The function to be removed from the event listeners.

    Returns void

    void

  • Removes the specified event listener for the 'blocked' event.

    Parameters

    • event: "blocked"

      The name of the event to remove the listener from.

    • listener: ConnectionEventListener

      The function to be removed from the event listeners.

    Returns void

    void

  • Removes the specified event listener for the 'unblocked' event. This event is emitted when the connection is unblocked after being blocked due to a flow control mechanism.

    Parameters

    • event: "unblocked"

      The name of the event to remove the listener from.

    • listener: ConnectionEventListener

      The function to be removed from the event listeners.

    Returns void

    void

  • Removes the specified event listener for the 'before:close' event. This event is emitted before the connection is closed.

    Parameters

    • event: "before:close"

      The name of the event to remove the listener from.

    • listener: ConnectionEventListener

      The function to be removed from the event listeners.

    Returns void

    void

  • Registers an event listener for the 'connected' event. This event is emitted when the connection is established.

    Parameters

    • event: "connected"

      The name of the event to listen for.

    • listener: ConnectionEventListener

      The function to be called when the event is emitted.

    Returns void

    void

  • Registers an event listener for the specified event.

    Parameters

    • event: "error"

      The name of the event to listen for.

    • listener: ConnectionErrorEventListener

      The function to be called when the event is emitted.

    Returns void

    void

  • Registers an event listener for the 'close' event.

    Parameters

    • event: "close"

      The name of the event to listen for.

    • listener: ConnectionCloseEventListener

      The function to be called when the event is emitted.

    Returns void

    void

  • Registers an event listener for the 'blocked' event. This event is emitted when the connection is blocked due to a flow control mechanism.

    Parameters

    • event: "blocked"

      The name of the event to listen for.

    • listener: ConnectionEventListener

      The function to be called when the event is emitted.

    Returns void

    void

  • Registers an event listener for the 'unblocked' event. This event is emitted when the connection is unblocked after being blocked due to a flow control mechanism.

    Parameters

    • event: "unblocked"

      The name of the event to listen for.

    • listener: ConnectionEventListener

      The function to be called when the event is emitted.

    Returns void

    void

  • Registers an event listener for the 'before:close' event. This event is emitted before the connection is closed.

    Parameters

    • event: "before:close"

      The name of the event to listen for.

    • listener: ConnectionEventListener

      The function to be called when the event is emitted.

    Returns void

    void

  • Registers a one-time event listener for the 'connected' event. The listener is automatically removed after it has been called once.

    Parameters

    • event: "connected"

      The name of the event to listen for.

    • listener: ConnectionEventListener

      The function to be called when the event is emitted.

    Returns void

    void

  • Registers a one-time event listener for the 'error' event. The listener is automatically removed after it has been called once.

    Parameters

    • event: "error"

      The name of the event to listen for.

    • listener: ConnectionErrorEventListener

      The function to be called when the event is emitted.

    Returns void

    void

  • Registers a one-time event listener for the 'close' event. The listener is automatically removed after it has been called once.

    Parameters

    • event: "close"

      The name of the event to listen for.

    • listener: ConnectionCloseEventListener

      The function to be called when the event is emitted.

    Returns void

    void

  • Registers a one-time event listener for the 'blocked' event. The listener is automatically removed after it has been called once.

    Parameters

    • event: "blocked"

      The name of the event to listen for.

    • listener: ConnectionEventListener

      The function to be called when the event is emitted.

    Returns void

    void

  • Registers a one-time event listener for the 'unblocked' event. The listener is automatically removed after it has been called once. This event is emitted when the connection is unblocked after being blocked due to a flow control mechanism.

    Parameters

    • event: "unblocked"

      The name of the event to listen for.

    • listener: ConnectionEventListener

      The function to be called when the event is emitted.

    Returns void

    void

  • Registers a one-time event listener for the 'before:close' event. This event is emitted before the connection is closed. The listener is automatically removed after it has been called once.

    Parameters

    • event: "before:close"

      The name of the event to listen for.

    • listener: ConnectionEventListener

      The function to be called when the event is emitted.

    Returns void

    void

  • Closes the connection to the RabbitMQ server.

    Returns Promise<void>

    A Promise that resolves when the connection has been closed.

    Throws

    An error if the connection could not be closed.

    Remarks

    The reason we don't check if the connection is active and just return if it is already inactive is because the connection may be "blocked" and we want to allow the user to close the connection even if it is blocked. Also, this function cleans up any channels which were opened by the connection, and shuts down any queues which were created by the connection.

  • Returns a Promise that resolves to a Queue instance with the specified name. If a Queue instance with the specified name was already created by the instance of the connection, it is returned instead, allowing you to re-use an existing connection channel.

    Parameters

    Returns Promise<Queue>

    A Promise that resolves to a Queue instance.

    Throws

    An error if the queue could not be created / updated on the server.

  • Sets the amount of time to wait for the connection to become active or indicate closed / blocked before throwing an exception.

    Parameters

    • timeout: number

      The amount of time to wait for the connection to become active or indicate closed / blocked before throwing an exception.

    Returns void

    Throws

    An error if the timeout is not an integer greater than or equal to 100 (100ms).

    Since

    1.0.9

    Remarks

    This value is used internally by the Connection class to determine how long to wait for the connection to become active or indicate closed / blocked before throwing an exception

  • Returns a Promise that resolves when the connection is active.

    Parameters

    • timeout: number = 1000

      The maximum time to wait for the connection to become active.

    Returns Promise<void>

    A Promise that resolves when the connection is active.

    Throws

    An error if the connection is not active within the specified timeout or is closed / blocked before becoming active.

    Since

    1.0.9

  • Closes all active connections.

    Returns Promise<void>

    A Promise that resolves when all connections have been closed.

    Throws

    An error if any of the connections cannot be closed.

    Since

    1.0.12

    Remarks

    When the Connection class is imported, due to Live Bindings, this function will be able to close all connections that are created after the import. However, when the class is required as opposed to imported, this function will only be able to close connections that are created from within the file it is required in.