Partition and Replication Factor.

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

Kafka maintains feeds of messages in categories called topics.

Sagar Kudu

--

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

--

--

Sagar Kudu

I am Full Stack Java Developer @ Tata Strive | Get blogs and tutorials related to the (React | Kafka | DevOps) | Connect https://www.linkedin.com/in/sagarkudu/