Skip to content

Instantly share code, notes, and snippets.

@ashutoshsahoo
Created February 11, 2022 18:47
Kafka commands

Kafka Commands

Create topic

  • Check version
kafka-topics --version
  • Create topic
kafka-topics --bootstrap-server 127.0.0.1:9092 --topic first-topic --create --partitions 3 --replication-factor 1

N.B.: With single node kafka, the replication factor can't be more than one.

  • List topics
kafka-topics --bootstrap-server 127.0.0.1:9092 --list
  • Describe topic
 kafka-topics --bootstrap-server 127.0.0.1:9092 --topic first-topic --describe
  • Delete topic
kafka-topics --bootstrap-server 127.0.0.1:9092 --topic second-topic --delete

Publish messsage : Kafka producer

  • Publish messages
kafka-console-producer --bootstrap-server 127.0.0.1:9092 --topic first-topic
  • Publish messages with acks=all
 kafka-console-producer --bootstrap-server 127.0.0.1:9092 --topic first-topic --producer-property acks=all

Consume messages : Kafka consumer

  • Consume messages
kafka-console-consumer --bootstrap-server 127.0.0.1:9092 --topic first-topic
  • Consume messages from beginning
kafka-console-consumer --bootstrap-server 127.0.0.1:9092 --topic first-topic --from-beginning
  • Consume messages with consumer group
kafka-console-consumer --bootstrap-server 127.0.0.1:9092 --topic first-topic --group my-first-application

Consumer Groups

  • Lists
kafka-consumer-groups --bootstrap-server 127.0.0.1:9092 --list
  • Describe
kafka-consumer-groups --bootstrap-server 127.0.0.1:9092 --group my-first-application --describe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment