Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

kafka-topics

The Apache Kafka command-line tools: create and inspect topics, produce and consume messages, and check consumer lag.

Niveau
DevSecOps-service
Groep
Databases en messaging
Root nodig
Nee
Pakket
kafka
Ook
kafka, kafka-topics.sh, kafka-console-consumer

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

Apache Kafka is a distributed event log: producers write records to topics; topics are split into partitions and copied to several brokers (replication). Consumers in a consumer group share the partitions and remember their offset. Kafka carries logs, metrics, clicks, orders and change-data-capture between systems. Kafka 4 runs without ZooKeeper (KRaft). The tools are shell scripts in bin/ (kafka-topics.sh …); some packages drop the .sh.

Managed versions: Azure Event Hubs (Kafka API), Confluent Cloud, AWS MSK. On Kubernetes: the Strimzi operator.

Zo schrijf je het

kafka-topics.sh --bootstrap-server HOST:9092 --create|--list|--describe|--alter|--delete [--topic NAME]
kafka-console-producer.sh / kafka-console-consumer.sh --bootstrap-server HOST:9092 --topic NAME

Belangrijkste delen

Tools

kafka-topics.sh
Create, list, describe topics.
kafka-console-producer.sh
Write messages from the terminal.
kafka-console-consumer.sh
Read messages.
kafka-consumer-groups.sh
Groups, offsets, lag.
kafka-configs.sh
Topic and broker settings (retention).
kafka-acls.sh
Access control lists.
kafka-storage.sh
Format storage for KRaft.

Opties 7

Meest gebruikt

Flags

--bootstrap-server HOST:9092
A broker to connect to.
--topic NAME
Topic.
--partitions N / --replication-factor N
Size and copies (create).
--from-beginning
Read from the oldest message.
--group NAME
Consumer group.
--command-config FILE
Client settings (TLS, SASL).
--describe / --list
Show details / names.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Run Kafka (KRaft) in a container for a lab

    podman run -d --name kafka -p 127.0.0.1:9092:9092 docker.io/apache/kafka:3.8.1
  2. 2Create and describe a topic

    kafka-topics.sh --bootstrap-server localhost:9092 --create --topic shop.orders --partitions 6 --replication-factor 1
    kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic shop.orders
  3. 3Send and read test messages

    echo '{"id": 1, "total": 49.90}' | kafka-console-producer.sh --bootstrap-server localhost:9092 --topic shop.orders
    kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic shop.orders --from-beginning --max-messages 5
  4. 4Check consumer lag (are consumers behind?)

    kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group invoice-service
  5. 5Reset a group to re-read a topic

    kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group invoice-service --topic shop.orders --reset-offsets --to-earliest --execute
  6. 6Set retention to 7 days

    kafka-configs.sh --bootstrap-server localhost:9092 --alter --entity-type topics --entity-name shop.orders --add-config retention.ms=604800000
  7. 7Connect with TLS and SASL

    cat client.properties
    security.protocol=SASL_SSL
    sasl.mechanism=SCRAM-SHA-512
    sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="shop" password="Example-Only";
    ssl.truststore.location=/etc/kafka/truststore.jks
    kafka-topics.sh --bootstrap-server kafka.lab.local:9093 --command-config client.properties --list
  8. 8Allow a user to read one topic (ACL)

    kafka-acls.sh --bootstrap-server kafka.lab.local:9093 --command-config admin.properties --add --allow-principal User:invoice --operation Read --topic shop.orders --group invoice-service
  9. 9List all topics

    kafka-topics.sh --bootstrap-server localhost:9092 --list
  10. 10Strimzi on Kubernetes: a topic as YAML

    cat topic.yaml
    apiVersion: kafka.strimzi.io/v1beta2
    kind: KafkaTopic
    metadata: { name: shop.orders, labels: { strimzi.io/cluster: lab } }
    spec: { partitions: 6, replicas: 3 }

Let op

  • You can add partitions but never remove them; plan the count (and keys change partitions when you add).
  • Without TLS and SASL anyone on the network can read and write all topics.
  • Watch consumer lag — growing lag means data waits and may expire.

Bestanden

config/server.properties
Broker settings.
client.properties
Client TLS/SASL settings (keep private).

Tips om te onthouden

  • Name topics domain.entity[.event] (shop.orders.created) and keep the schema in a registry.

Exitcodes

0Success.
1Error.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man kafka-topics