Useful Apache Kafka Console Commands

Parameters used:

Parameter Comment
zookeeper_host the list of Zookeeper nodes in cluster
topic_name the topic name
broker_list the list of Kafka brokers in cluster
replication_factor the replication factor for topic
partition_count the number of partitions for topic

Topic management:

  • create a topic:
bin/ --create --zookeeper [zookeeper_list] --replication-factor [replication_factor] --partitions [partition_count] --topic [topic_name]


>bin/ --create --zookeeper zookeeeper_nd1:2181,zookeeper_nd2:2181,zookeeper_nd3:2181 --replication-factor 1  --partitions 3 --topic TestKafkaTopicName
  • view list of topics
bin/ --list --zookeeper [zookeeper_list]


>bin/ --list --zookeeper zookeeeper_nd1:2181,zookeeper_nd2:2181,zookeeper_nd3:2181
  • describe a topic
bin/ --describe --zookeeper [zookeeper_list] --topic [topic_name]


>bin/ --describe --zookeeper zookeeeper_nd1:2181,zookeeper_nd2:2181,zookeeper_nd3:2181 --topic TestKafkaTopicName


  • produce a message to Kafka
bin/ --broker-list [broker_list] --topic [topic_name]


>bin/  --broker-list kafka_nd1:6667,kafka_nd2:6667,kafka_nd3:6667 --topic TestKafkaTopicName

Note: you have to be extremely accurate when sending a message to Kafka from console because the message might be in incorrect format that would break the consumer logic.
  • consume all messages from Kafka topic (old ones and new arriving)
bin/ --zookeeper [zookeeper_list] --topic [topic_name] --from-beginning


>bin/ --zookeeper zookeeeper_nd1:2181,zookeeper_nd2:2181,zookeeper_nd3:2181 --topic TestKafkaTopicName
  • consume  the messages arriving in Kafka topic
bin/ --zookeeper [zookeeper_list] --topic [topic_name] --from-beginning


>bin/ --zookeeper zookeeeper_nd1:2181,zookeeper_nd2:2181,zookeeper_nd3:2181 --topic TestKafkaTopicName

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s