Kafka Windows CLI Commands

access_time 2 months ago visibility94 comment 0

This page summarizes commonly used Apache Kafka Windows commands. 


Setup an environment variable named KAFKA_HOME that points to where Kafka is located. 


SET KAFKA_HOME=F:\big-data\kafka_2.13-2.6.0
warning Remember to change the server address, port number and Kafka topic name accordingly before running any of the following command. 

Start Kafka brokers (incl. ZookKeeper)

%KAFKA_HOME%/bin/windows/zookeeper-server-start.bat %KAFKA_HOME%/config/zookeeper.properties
%KAFKA_HOME%/bin/windows/kafka-server-start.bat %KAFKA_HOME%/config/server.properties

Stop Kafka brokers

%KAFKA_HOME%/bin/windows/kafka-server-stop.bat %KAFKA_HOME%/config/server.properties
%KAFKA_HOME%/bin/windows/zookeeper-server-stop.bat %KAFKA_HOME%/config/zookeeper.properties

Kafka topic command

Command must include exactly one action: --list, --describe, --create, --alter or --delete
Option                                   Description
------                                   -----------
--alter                                  Alter the number of partitions,
                                           replica assignment, and/or
                                           configuration for the topic.
--at-min-isr-partitions                  if set when describing topics, only
                                           show partitions whose isr count is
                                           equal to the configured minimum. Not
                                           supported with the --zookeeper
--bootstrap-server <String: server to    REQUIRED: The Kafka server to connect
  connect to>                              to. In case of providing this, a
                                           direct Zookeeper connection won't be
--command-config <String: command        Property file containing configs to be
  config property file>                    passed to Admin Client. This is used
                                           only with --bootstrap-server option
                                           for describing and altering broker
--config <String: name=value>            A topic configuration override for the
                                           topic being created or altered.The
                                           following is a list of valid
                                         See the Kafka documentation for full
                                           details on the topic configs.It is
                                           supported only in combination with --
                                           create if --bootstrap-server option
                                           is used.
--create                                 Create a new topic.
--delete                                 Delete a topic
--delete-config <String: name>           A topic configuration override to be
                                           removed for an existing topic (see
                                           the list of configurations under the
                                           --config option). Not supported with
                                           the --bootstrap-server option.
--describe                               List details for the given topics.
--disable-rack-aware                     Disable rack aware replica assignment
--exclude-internal                       exclude internal topics when running
                                           list or describe command. The
                                           internal topics will be listed by
--force                                  Suppress console prompts
--help                                   Print usage information.
--if-exists                              if set when altering or deleting or
                                           describing topics, the action will
                                           only execute if the topic exists.
--if-not-exists                          if set when creating topics, the
                                           action will only execute if the
                                           topic does not already exist.
--list                                   List all available topics.
--partitions <Integer: # of partitions>  The number of partitions for the topic
                                           being created or altered (WARNING:
                                           If partitions are increased for a
                                           topic that has a key, the partition
                                           logic or ordering of the messages
                                           will be affected). If not supplied
                                           for create, defaults to the cluster
--replica-assignment <String:            A list of manual partition-to-broker
  broker_id_for_part1_replica1 :           assignments for the topic being
  broker_id_for_part1_replica2 ,           created or altered.
  broker_id_for_part2_replica1 :
  broker_id_for_part2_replica2 , ...>
--replication-factor <Integer:           The replication factor for each
  replication factor>                      partition in the topic being
                                           created. If not supplied, defaults
                                           to the cluster default.
--topic <String: topic>                  The topic to create, alter, describe
                                           or delete. It also accepts a regular
                                           expression, except for --create
                                           option. Put topic name in double
                                           quotes and use the '\' prefix to
                                           escape regular expression symbols; e.
                                           g. "test\.topic".
--topics-with-overrides                  if set when describing topics, only
                                           show topics that have overridden
--unavailable-partitions                 if set when describing topics, only
                                           show partitions whose leader is not
--under-min-isr-partitions               if set when describing topics, only
                                           show partitions whose isr count is
                                           less than the configured minimum.
                                           Not supported with the --zookeeper
--under-replicated-partitions            if set when describing topics, only
                                           show under replicated partitions
--version                                Display Kafka version.
--zookeeper <String: hosts>              DEPRECATED, The connection string for
                                           the zookeeper connection in the form
                                           host:port. Multiple hosts can be
                                           given to allow fail-over.

List Kafka topics

%KAFKA_HOME%/bin/windows/kafka-topics.bat --list --bootstrap-server localhost:9092

Create Kafka topic

%KAFKA_HOME%/bin/windows/kafka-topics.bat --create --topic kontext-kafka --bootstrap-server localhost:9092

Describe Kafka topic

%KAFKA_HOME%/bin/windows/kafka-topics.bat --describe --topic kontext-kafka --bootstrap-server localhost:9092

Example output:

Topic: kontext-kafka    PartitionCount: 3       ReplicationFactor: 1    Configs: segment.bytes=1073741824
        Topic: kontext-kafka    Partition: 0    Leader: 0       Replicas: 0     Isr: 0
        Topic: kontext-kafka    Partition: 1    Leader: 0       Replicas: 0     Isr: 0
        Topic: kontext-kafka    Partition: 2    Leader: 0       Replicas: 0     Isr: 0

*In my Kafka environment, there is only one node thus Leader is always 0 and replica is also 0. 

Delete Kafka topic

%KAFKA_HOME%/bin/windows/kafka-topics.bat --delete --topic kontext-kafka --bootstrap-server localhost:9092
copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Want to publish your article on Kontext?

Learn more

Kontext Column

Created for everyone to publish data, programming and cloud related articles.
Follow three steps to create your columns.

Learn more arrow_forward

More from Kontext

local_offer kafka local_offer python

visibility 98
thumb_up 0
access_time 2 months ago

Apache Kafka is written with Scala. Thus, the most natural way is to use Scala (or Java) to call Kafka APIs, for example, Consumer APIs and Producer APIs. For Python developers, there are open source packages available that function similar as official Java clients.  This article shows you ...

local_offer shell

visibility 14
thumb_up 0
access_time 12 months ago

Environment variables are commonly used in many frameworks or programs.

local_offer hadoop local_offer shell

visibility 147
thumb_up 0
access_time 12 months ago

Hadoop provides a number of CLIs that can be used to perform many tasks/activities. This code snippet shows you how to check file/folder size in HDFS.

About column

Streaming analytics related tutorials and ideas.

rss_feed Subscribe RSS