Partition and Replication Factor.

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

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

Producers write data to topics and consumers read from topics.

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 (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 ←



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sagar Kudu

Sagar Kudu

I am Full Stack Java Developer @ Tata Strive | Get blogs and tutorials related to the (React | Kafka | DevOps) | Follow me on LinkedIn