Kafka Cheat Sheet

This cheat sheet contains all commonly used commands, while you work with Kafka console. But, it is difficult to keep remember all these commands and you prepare stickies to make these noted down. But now, no more stickies of Git. You can use this cheat sheet as your sticky notes. 

Topics
  • Create Topic
    bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --partitions 1 --replication-factor 1 --topic <topic-name>

  • Delete Topic
    bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic <topic-name>

  • List Topic
    bin/kafka-topics.sh --bootstrap-server localhost:9092 --list

  • Describe Topic
    bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic <topic-name>


Consumer Console
  • Listen messages from topic in consumer
    bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic <topic-name> --from-beginning

    Note: If you want to see all messages from beginning you can use option --from-beginning

Producer Console
  • Publish messages in topic
    bin/kafka-console-producer.sh --broker-list localhost:9092 --topic <topic-name>

Consumer Group
  • Create consumer group
    bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic <topic-name> --from-beginning --consumer-property group.id=<group-id-name>

  • Consumer group list
    bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list

  • Describe consumer group
    bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group <topic-name>


Describe config for topic
  • bin/kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type topics --entity-name <topic-name>

Note:
  • If you are using Kafka older version like =< 2.11-1.0.0 then in place of --bootstrap-server localhost:9092 use --zookeeper localhost:2181
  • 9092 is the default port for Kafka and 2181 for zookeeper. If you are different ports please use those.
  • If you are using --bootstrap-server then with localhost you need to provide kafka port.
  • If you are using --zookeeper then with localhost you need to provide zookeeper port.

Comments