Partition and Replication Factor.

How to create Topics with Partitions & Replication factor using Kafka?

Kafka maintains feeds of messages in categories called topics.

Please make sure that you have started the server. Learn How to start the server in Kafka?

Since Kafka is a distributed system, topics are partitioned and replicated across multiple nodes. Kafka treats each topic partition as a log (an ordered set of messages). Each message in a partition is assigned a unique offset.

Each topic has a user-defined category (or feed name), to which messages are published.

Create a Topic

To create a Kafka topic, run kafka-topics.bat (windows) or kafka-topics.sh (Mac or Linux) and specify the topic name, replication factor, and other attributes:

The following example creates a topic named “test-topic”, with 4 partitions and 1 replica:

.\bin\windows\kafka-topics.bat --create --topic test-topic -zookeeper localhost:2181 --replication-factor 1 --partitions 4
test-topic is created

View or List all the Topics

To view the topic, run the list topic command:

.\bin\windows\kafka-topics.bat --list --zookeeper localhost:2181

-> you can see Topic is listed with the name “test-topic

The auto.create.topics.enable property, when set to true, automatically creates topics when applications attempt to produce, consume, or fetch metadata for a nonexistent topic.

Kafka Tutorials

Next →

Previous ←

Software Engineer at HCL | Technical Content Writing | Follow me on LinkedIn https://www.linkedin.com/in/sagarkudu/