Managing Topics
On this section you will learn how to create, list, delete topics within your Kafka cluster
What is a Topic ?
A topic is described as a Stream of messages of a particular type. For example:
Debit Transactions
Credit Transactions
Topics are broken down one level more of granularity, they are formed by partitions.
Messages are written to it in an append-only fashion, and are read in order from beginning to end. There are no guarantee of ordering in a topic, but there is guarantee of ordering on the partition

Docker hint
To start working with your cli, enter to the docker container by executing the following commands
From you bin folder, there is an script called kafka-topics.sh or kafka-topics.bat , and it will facilitate for you the creation of a Topic in your cluster
Go ahead and explore the options available for working with Topics via CLI
Kafka Topics Help
./kafka-topics.sh --help
Create a Topic
Now that you have explored a bit the command line, go ahead and create a topic with the following conditions:
Topic name: wwcode
Number of Partitions: 2
Replicas: 1
Hint
./kafka-topics.sh --create ....
Bonus exercise
Try to create the same topic only if it doesn't exist.
List a Topic
When working with Kafka, you are most likely curious to see what is going on with your topic, if It was already created/updated/deleted, if the replicas are in sync or what is the partition leader.
Go ahead and list your topics by executing:
Info
When listing your topics, we need to provide the zookeeper list, since Zookeeper is the one who keeps a record of the topics and Kafka underneath goes and query zookeeper to retrieve the topics for your cluster.
Bonus Exercise
Try to gather a full detailed description of the topic, specifically retrieve, PartitionCount, ReplicationFactor, and ISR ( In Sync Replicas)
Delete a Topic ( Danger )
There might be cases when you would like to delete a Topic. For example, there is type of event that will be retired from your application and you would like to delete this topic to avoid writing to a topic that won't be used anymore.
Go ahead and try to delete the topic you just have created before.
Bonus Exercise
Try to delete a topic that does not exist and see what happens. How you could solve this issue?
Last updated