$ ./bin/kafka-topics.sh
Create, delete, describe, or change a topic.
TopicCommand Command-Line Tool — Topic Management on Command Line
kafka.admin.TopicCommand is a command-line tool that can alter, create, delete, describe and list topics in a Kafka cluster.
| Action | Description |
|---|---|
TopicCommand can be executed using kafka-topics shell script (i.e. bin/kafka-topics.sh or bin\windows\kafka-topics.bat).
| Option | Description |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ ./bin/kafka-topics.sh \
--create \
--zookeeper :2181 \
--replication-factor 1 \
--partitions 1 \
--topic my-topic
$ ./bin/kafka-topics.sh --list --zookeeper :2181
my-topic
$ ./bin/kafka-topics.sh \
--zookeeper :2181 \
--describe \
--topic my-topic
Topic:my-topic PartitionCount:1 ReplicationFactor:1 Configs:
Topic: my-topic Partition: 0 Leader: 0 Replicas: 0 Isr: 0
alterTopic Method
alterTopic(zkClient: KafkaZkClient, opts: TopicCommandOptions): Unit
alterTopic…FIXME
|
Note
|
alterTopic is used when…FIXME
|
Creating Topic — createTopic Method
createTopic(zkClient: KafkaZkClient, opts: TopicCommandOptions): Unit
createTopic takes the values of topic, config and if-not-exists options.
createTopic creates a new AdminZkClient (with the input KafkaZkClient).
createTopic branches off per replica-assignment option’s existence:
-
With replica-assignment,
createTopicrequests theAdminZkClientto createOrUpdateTopicPartitionAssignmentPathInZK (with theupdateflag off) -
With no replica-assignment,
createTopicchecks the required arguments, i.e. partitions and replication-factor, and together with disable-rack-aware flag requests theAdminZkClientto create the topic
In the end, createTopic prints out the following:
Created topic "[topic]"
|
Note
|
createTopic is used exclusively when TopicCommand is executed with --create action.
|
deleteTopic Method
deleteTopic(zkClient: KafkaZkClient, opts: TopicCommandOptions): Unit
deleteTopic…FIXME
|
Note
|
deleteTopic is used when…FIXME
|
describeTopic Method
describeTopic(
zkClient: KafkaZkClient,
opts: TopicCommandOptions): Unit
describeTopic…FIXME
|
Note
|
describeTopic is used when…FIXME
|
listTopics Method
listTopics(zkClient: KafkaZkClient, opts: TopicCommandOptions): Unit
listTopics…FIXME
|
Note
|
listTopics is used when…FIXME
|
Executing Standalone Application — main Method
main(args: Array[String]): Unit
main is the entry point of the TopicCommand standalone application when launched on command line (e.g. from bin/kafka-topics.sh).
main creates a TopicCommandOptions.
main prints out the following message and exits when no command-line arguments were given:
Create, delete, describe, or change a topic.
main prints out the following message and exits when no action was specified:
Command must include exactly one action: --list, --describe, --create, --alter or --delete
main makes sure the action and the options were all valid.
main creates a new KafkaZkClient (with the zookeeper option).
main branches off per the action.
In case of any exception, main prints out the following and exits with 1 exit code:
Error while executing topic command : [message]
getTopics Internal Method
getTopics(zkClient: KafkaZkClient, opts: TopicCommandOptions): Seq[String]
getTopics…FIXME
|
Note
|
getTopics is used when TopicCommand is requested to alterTopic, listTopics, deleteTopic, describeTopic.
|