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

    Class AMQPSession<P, C, KP, KC>

    High-level session with automatic reconnection and consumer recovery.

    The generic parameters thread parser/coder type information through all session-owned handles (queues, exchanges, RPC clients/servers).

    Users never write the generics explicitly — they're inferred from the connect() call.

    Create via AMQPSession.connect(url, options).

    Type Parameters

    • P extends ParserMap = {}
    • C extends CoderMap = {}
    • KP extends keyof P & string = never
    • KC extends keyof C & string = never
    Index

    Accessors

    • get closed(): boolean

      true when the underlying connection is closed.

      Returns boolean

    Methods

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

      Subsequent calls with the same (non-empty) name return the cached handle without redeclaring, and options on those calls are ignored.

      Server-named queues (declared with "") are not cached or tracked for auto-recovery: every call declares a fresh queue, and the broker assigns a new name on every connection, so the old name is dead after a reconnect and can't be recovered. Neither the queue nor its consumers are auto-recovered — AMQPQueue.subscribe() recovery does not apply here. Re-declare such a queue in an AMQPSessionOptions.onconnect handler — it runs again after every reconnect — and bind/subscribe there.

      Parameters

      • name: string

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

      • Optionaloptions: QueueOptions

        queue declaration parameters and queue arguments

      Returns Promise<AMQPQueue<P, C, KP, KC>>

    • 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: ResolveBody<P, KP>

        The request body

      • Optionaloptions: AMQPProperties & { timeout?: number }

        Optional AMQP properties and timeout

        • Optionaltimeout?: number

          Timeout in milliseconds

      Returns Promise<AMQPMessage<P>>

      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<P, KP>

        Callback that receives the decoded message, returns the response body

      • Optionalprefetch: number

        Channel prefetch count (default: 1)

      Returns Promise<AMQPRPCServer<P, C, KP, KC>>

      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)

      Type Parameters

      • P extends ParserMap = {}
      • C extends CoderMap = {}
      • KP extends string = never
      • KC extends string = never

      Parameters

      Returns Promise<AMQPSession<P, C, KP, KC>>