@qualithm/kafka-client - v0.1.6
    Preparing search index...

    Class ConnectionPool

    A pool of connections to Kafka brokers.

    Manages connections with configurable maximum connections per broker. Connections are created lazily on first request and reused for subsequent requests to the same broker. Supports broker discovery from metadata to learn about all brokers in the cluster.

    const pool = new ConnectionPool({
    bootstrapBrokers: [{ host: "localhost", port: 9092 }],
    socketFactory: createNodeSocketFactory(),
    })
    await pool.connect()
    const conn = await pool.getConnection("localhost", 9092)
    // use conn.send(...)
    pool.releaseConnection(conn)
    await pool.close()
    Index

    Constructors

    Accessors

    Methods

    • Close all connections and shut down the pool.

      Rejects any pending waiters and closes all idle and active connections.

      Returns Promise<void>

    • Connect to the cluster by discovering brokers from metadata.

      Contacts one of the bootstrap brokers to learn about all brokers in the cluster. Must be called before getConnection.

      Returns Promise<void>

      If the pool is already closed or no brokers are reachable.

    • Get the number of connections (idle + active) for a specific broker.

      Parameters

      • host: string
      • port: number

      Returns number

    • Refresh broker metadata by re-running discovery.

      Useful when the cluster topology changes (e.g. brokers added/removed). Uses discovered brokers first, falling back to bootstrap addresses.

      Returns Promise<void>

      If the pool is closed or no brokers are reachable.

    • Release a connection back to the pool.

      Makes the connection available for reuse. If waiters are pending, the connection is given to the first waiter instead of returning to the idle list.

      Parameters

      Returns void