@cloudamqp/amqp-client
    Preparing search index...

    Class AMQPSession

    High-level session with automatic reconnection and consumer recovery.

    Create via AMQPSession.connect(url, options).

    Index

    Properties

    onconnect?: () => void

    Fires after a successful (re)connection and consumer recovery

    onfailed?: (error?: Error) => void

    Fires when max retries are exhausted

    Accessors

    • get closed(): boolean

      true when the underlying connection is closed.

      Returns boolean

    Methods

    • Declare an exchange and return a session-bound AMQPExchange handle.

      Parameters

      • name: string

        exchange name

      • type: string

        exchange type: "direct", "fanout", "topic", "headers", or a custom type

      • Optionalparams: ExchangeParams

        exchange declaration parameters

      • Optionalargs: Record<string, unknown>

        optional exchange arguments

      Returns Promise<AMQPExchange>

    • Declare a queue and return a session-bound AMQPQueue handle. The returned queue's subscribe uses auto-recovery and publish waits for a broker confirm.

      Parameters

      • name: string

        queue name (use "" to let the broker generate a name)

      • Optionalparams: QueueParams

        queue declaration parameters

      • Optionalargs: Record<string, unknown>

        optional queue arguments (e.g. x-message-ttl)

      Returns Promise<AMQPQueue>

    • Perform an RPC call: publish a message and wait for the response. Creates a temporary client per call — simple and sufficient for most use cases.

      For high-throughput scenarios where the per-call channel overhead matters, use rpcClient to create a reusable client instead.

      Parameters

      • queue: string

        The routing key / queue name of the RPC server

      • body: Body

        The request body

      • Optionaloptions: AMQPProperties & { timeout?: number }

        Optional AMQP properties and timeout

        • Optionaltimeout?: number

          Timeout in milliseconds

      Returns Promise<AMQPMessage>

      The reply AMQPMessage

    • Create and start an RPC server that consumes from the given queue. Each incoming message is passed to handler; the returned value is published back to the caller's replyTo address.

      Parameters

      • queue: string

        Queue name to consume from

      • handler: RPCHandler

        Callback that receives the message body and full message, returns the response body

      • Optionalprefetch: number

        Channel prefetch count (default: 1)

      Returns Promise<AMQPRPCServer>

      A started AMQPRPCServer

    • Stop the session: cancel reconnection, clear consumer tracking, and close the underlying connection.

      Parameters

      • Optionalreason: string

      Returns Promise<void>

    • Connect to an AMQP broker and return a session with automatic reconnection.

      The transport is chosen from the URL scheme:

      • amqp:// / amqps:// → TCP socket (AMQPClient)
      • ws:// / wss:// → WebSocket (AMQPWebSocketClient)

      Parameters

      Returns Promise<AMQPSession>