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
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
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 “
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.
How to Publish and Subscribe messages using Kafka?
Apache Kafka is a publish-subscribe-based durable messaging system. A messaging system sends messages between…