TopicCommand — Topic Management on Command Line

kafka.admin.TopicCommand is a command-line application that can alter, create, delete, describe and list topics in a Kafka cluster.

Table 1. TopicCommand’s Actions
Action Description

--alter

Alters the number of partitions, replica assignment, and/or configuration of a topic or topics

--create

Creates a new topic

--delete

Deletes a topic or topics

--describe

Describes a topic or topics

--list

Lists available topics

TopicCommand can be executed using kafka-topics shell script (i.e. bin/kafka-topics.sh or bin\windows\kafka-topics.bat).

$ ./bin/kafka-topics.sh
Create, delete, describe, or change a topic.
Table 2. TopicCommand’s Options
Option Description

config

A topic configuration override for the topic being worked on (as name=value)

disable-rack-aware

Disable rack aware replica assignment

if-not-exists

When creating a topic(s), the action will only execute if the topic does not already exist

partitions

The number of partitions of 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.

replica-assignment

A list of manual partition-to-broker assignments for the topic being created or altered

replication-factor

The replication factor for each partition of the topic being created

topic

A topic or topics to be altered, created, deleted, or listed and described (through getTopics)

$ ./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:

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.

results matching ""

    No results matching ""