Search code examples
javascripttypescriptkafkajs

kafkajs disconnect takes a long time


I use kafkajs for autotests.

When calling await consumer.disconnect() - the command takes about 5 seconds, are there any options for a safe and fast disconnect?

    const consumer = this.client.consumer({
        groupId: this.groupId,
        heartbeatInterval: this.heartbeatInterval,
        sessionTimeout: this.sessionTimeout,
    });

    await consumer.connect();
    await consumer.subscribe({ topics: [topic], fromBeginning });
    await consumer.run({...});
    await this.disconnect(consumer);

Solution

  • The maximum amount of time in milliseconds the server will block before answering the fetch request if there isn’t sufficient data to immediately satisfy the requirement given by minBytes

    const consumer = this.client.consumer({
        minBytes: 0,
        // or
        maxWaitTimeInMs: 0,
        ...
    });