Yes, there are more parameters than --create. To check whether a topic has been successfully created, run the kafka-topics command with the --list parameter:
> ./bin/kafka-topics.sh --list --ZooKeeper localhost:2181 humbleTopic
This parameter returns the list of all the existent topics in the Kafka cluster.
To get the details of a particular topic, run the kafka-topics command with the --describe parameter:
> ./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic humbleTopic
The command output is:
Topic:humbleTopic PartitionCount:1 ReplicationFactor:1 Configs:
Topic: humbleTopic Partition: 0 Leader: 1 Replicas: 1 Isr: 1
The explanation of the output is:
- PartitionCount: Number of partitions existing on this topic.
- ReplicationFactor: Number of replicas existing on this topic.
- Leader: Node responsible for the reading and writing operations of a given partition.
- Replicas: List of brokers replicating the Kafka data. Some of these might even be dead.
- ISR: List of nodes that are currently in-sync replicas.
To create a topic with multiple replicas, we need to increase the replication factor as follows:
> ./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 1 --topic replicatedTopic
The output is as follows:
Created topic "replicatedTopic".
Call the kafka-topics command with the --describe parameter to check the topic details:
> ./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic replicatedTopic
Topic:replicatedTopic PartitionCount:1 ReplicationFactor:2 Configs:
Topic: replicatedTopic Partition: 0 Leader: 1 Replicas: 1,2 Isr: 1,2
As Replicas and ISR (in-sync replicas) are the same lists, all the nodes are in-sync.
Try to play with all these commands; try to create replicated topics on dead servers and see the output. Also, create topics on running servers and then kill them to see the results.
As mentioned before, all the commands executed through the command line can be executed programmatically.