Skip to content

Instantly share code, notes, and snippets.

@MirzaLeka
Last active July 27, 2026 05:16
Show Gist options
  • Select an option

  • Save MirzaLeka/2d564dbb4887410c4e0907b7bdbc2325 to your computer and use it in GitHub Desktop.

Select an option

Save MirzaLeka/2d564dbb4887410c4e0907b7bdbc2325 to your computer and use it in GitHub Desktop.
Kafka survival guide

Get committed offets on Kafka consumer

The guide explains how to inspect consumer using Kafka CLI.

Find running Kafka container:

> docker ps | grep kafka

Enter your Kafka (docker) container:

> docker exec -it <your-kafka-container> bash

Install Kafka CLI (only once)

Verify Dependencies

Verify Java is installed

> java -version

# openjdk version "21.0.11" 2026-04-21 LTS
# OpenJDK Runtime Environment Temurin-21.0.11+10 (build 21.0.11+10-LTS)
# OpenJDK 64-Bit Server VM Temurin-21.0.11+10 (build 21.0.11+10-LTS, mixed mode, sharing)

Wget (installation tool)

> which wget
# /usr/bin/wget

Tar (unzip tool)

> which tar
# /bin/tar

Install CLI:

Enter tmp directory to be able to download things

> cd /tmp

Download Kafka installer

> wget https://archive.apache.org/dist/kafka/3.7.0/kafka_2.13-3.7.0.tgz

Unzip files:

> tar -xvf kafka_2.13-3.7.0.tgz

Enter unzipped directory:

> cd kafka_2.13-3.7.0/bin

Kafka Groups: commands to run

List active groups (within the Broker):

> ./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list

# group1
# group2
# group3

Inspect your group:

> ./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group <your-group>
$:/tmp/kafka_2.13-3.7.0/bin$ ./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group red-group

GROUP           TOPIC           PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             CONSUMER-ID                                      HOST            CLIENT-ID
red-group       first-topic     0          10              10              0               my-node-app-48dcd40e-4bec-4d71-92d0-6931d3586f8b /172.18.0.1     my-node-app

Inspect all groups:

> ./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --all-groups
const { Kafka, logLevel } = require('kafkajs');
const kafka = new Kafka({
clientId: 'my-node-app',
brokers: ['localhost:9092'],
logLevel: logLevel.NOTHING,
retry: {
initialRetryTime: 300,
retries: 8
}
});
const fetchOffsets = async () => {
const admin = kafka.admin();
await admin.connect();
const offsets = await admin.fetchTopicOffsets('first-topic');
console.log(offsets);
await admin.disconnect();
};
fetchOffsets().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment