Get started
Run klens and a one-broker Kafka cluster on your machine, then create a topic, write records, and follow a consumer group.
In this tutorial, we run klens next to a local Kafka broker with Docker Compose. We create a topic, write records to it, find them, watch them arrive live, and move the offsets of a consumer group. It takes about fifteen minutes.
You need Docker with Compose. Nothing else is installed on your machine.
Start Kafka and klens
First, we create a folder with two files.
-
Create a folder named
klens-tutorialand open a terminal in it. -
Create
compose.yamlwith one Kafka broker and klens.compose.yaml services: kafka: image: apache/kafka:4.1.0 environment: KAFKA_NODE_ID: 1 KAFKA_PROCESS_ROLES: broker,controller KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092 KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9093 KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0 klens: image: ghcr.io/marcocondrache/klens:latest ports: - "8080:8080" volumes: - ./config.yaml:/config.yaml:ro depends_on: - kafka -
Create
config.yaml. It names one cluster,local, and lets klens change it.config.yaml clusters: local: bootstrap_servers: [kafka:9092] writable: true -
Start both containers.
docker compose up -d -
Open
http://localhost:8080in a browser.
The Topics page of the local cluster opens. It lists no topics yet, since Show internal is off. The dot next to local in the cluster switcher turns green once klens has read the cluster.
This setup has no sign-in, and writable: true lets anyone who reaches port 8080 change the cluster. Keep it on your own machine.
Create a topic
Now, we create a topic for orders.
- Select Create topic.
- Enter
ordersas the Name and3as the Partitions. Leave Replication factor empty. - Select Create topic.
klens opens the orders topic. The header shows 3 partitions and 0 messages, and the Data tab shows No records.
Write a record
-
Select Produce record.
-
Keep the Key as Null, and enter this Value as Text.
{"id": 1, "item": "book", "status": "placed"} -
Select Produce.
The record opens in a side sheet. It shows the partition and the offset that Kafka stored it at, and the value as formatted JSON. Close the sheet. The Data tab now lists the record.
If klens shows NotLeaderForPartition, Kafka is still electing leaders for the new topic. Wait a second and select Produce again.
Write records from a producer
klens is mostly for watching what other programs do. Next, we write records with the console producer that ships in the Kafka image.
-
In the terminal, start the producer.
docker compose exec kafka /opt/kafka/bin/kafka-console-producer.sh \ --bootstrap-server kafka:9092 --topic orders -
Type these lines, pressing Enter after each one.
{"id": 2, "item": "lamp", "status": "placed"} {"id": 3, "item": "book", "status": "shipped"} -
Keep the producer running.
In klens, the Data tab shows the new records at the top, and the header counts 3 messages.
Find a record
- Type
bookin Search key or value….
The list keeps the two records whose value holds book. klens runs the search on the server, so it works the same on a topic with millions of records.
- Clear the search box.
Follow the topic live
-
Select Live in the mode switch. The dot on the button pulses, and the list shows Waiting for records.
-
In the producer terminal, type another line.
{"id": 4, "item": "pen", "status": "placed"}
The record appears in klens as soon as Kafka stores it. The live tail shows only records that arrive after it starts.
- Stop the producer with Ctrl+C.
Read the topic with a consumer group
Now, we read the topic with a consumer group and watch its lag.
-
Start a console consumer in the group
tutorial. It prints the four records.docker compose exec kafka /opt/kafka/bin/kafka-console-consumer.sh \ --bootstrap-server kafka:9092 --topic orders \ --group tutorial --from-beginning -
In klens, select Consumer Groups in the sidebar. The
tutorialgroup is Stable with one member and a lag of 0. -
Stop the consumer with Ctrl+C. Within about ten seconds, the group becomes Empty.
Move the offsets of the group
Last, we rewind the group so that it reads the topic again.
- Open the
tutorialgroup and select Reset offsets. - Keep Every committed topic and Earliest offset.
The Preview lists each partition of orders, with the committed offset, the new offset, and the lag after the reset. The lag after the reset adds up to 4.
- Select Reset offsets.
The Offsets tab now shows a total lag of 4. If you start the consumer again without --from-beginning, it prints all four records again.
Clean up
Stop and remove both containers.
docker compose downNext steps
You ran klens against a local broker, wrote and found records, followed a topic, and moved the offsets of a group. From here:
- Connect to a cluster over TLS or SASL, with a Schema Registry.
- Require sign-in before you share klens.
- Deploy klens on Kubernetes.
- Read how klens reads Kafka to see why its pages cost the brokers little.