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

    Class KafkaConsumer

    Kafka consumer with consumer group support.

    Handles the full consumer group lifecycle: joining, syncing, heartbeating, fetching records, committing offsets, and graceful shutdown.

    const consumer = new KafkaConsumer({
    connectionPool: kafka.connectionPool,
    groupId: "my-group",
    })

    consumer.subscribe(["my-topic"])
    await consumer.connect()

    while (running) {
    const records = await consumer.poll(1000)
    for (const record of records) {
    // process record
    }
    }

    await consumer.close()
    Index

    Constructors

    Accessors

    Methods

    • Gracefully close the consumer.

      Commits offsets (if auto-commit is enabled), leaves the consumer group, and stops all timers.

      Returns Promise<void>

    • Commit offsets for all consumed partitions.

      Commits the current fetch position for each assigned partition.

      Returns Promise<void>

    • Connect to the group coordinator and join the consumer group.

      Discovers the coordinator, joins the group, receives partition assignments, and starts heartbeating.

      Returns Promise<void>

    • Poll for new records from assigned partitions.

      Sends Fetch requests to the brokers holding the assigned partitions and returns any records received. If no records are available within the timeout, returns an empty array.

      Also handles rebalance signals from heartbeat responses and triggers rejoin when necessary.

      Parameters

      • Optional_timeoutMs: number

        Maximum time to wait for records (reserved for future use).

      Returns Promise<readonly ConsumerRecord[]>

      Consumer records from the assigned partitions.

    • Set the topics to subscribe to.

      Must be called before connect. Calling again after connecting will trigger a rejoin on the next poll.

      Parameters

      • topics: readonly string[]

        Topic names to subscribe to.

      Returns void