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

    Class KafkaConnection

    A single connection to a Kafka broker.

    Handles request/response correlation, protocol framing, and timeout management. Uses the injected SocketFactory for runtime-agnostic TCP/TLS connections.

    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    Properties

    host: string

    Broker hostname.

    port: number

    Broker port.

    Accessors

    • get connected(): boolean

      Whether the connection is established and not closed.

      Returns boolean

    Methods

    • Perform SASL authentication if configured.

      Must be called after connect() and before sending any other requests. Uses SaslHandshake (v1) to negotiate the mechanism, then SaslAuthenticate to exchange authentication tokens.

      Returns Promise<void>

      If authentication fails.

    • Close the connection and reject all pending requests.

      Returns Promise<void>

    • Establish the connection to the broker.

      Returns Promise<void>

      If already connected or previously closed.

      If the connection times out.

    • Send a request and wait for the correlated response.

      Automatically assigns a correlation ID, encodes the request header, frames the message, and returns a BinaryReader positioned after the response header (ready for API-specific body decoding).

      Parameters

      • apiKey: ApiKey

        API key for the request.

      • apiVersion: number

        API version for the request.

      • encodeBody: (writer: BinaryWriter) => void

        Callback to encode the request body.

      Returns Promise<BinaryReader>

      Reader positioned at the start of the response body.

      If not connected.

      If the request times out.