构建自己的 Kafka
If you're looking to truly understand Kafka's architecture by implementing a simplified version yourself, you've come to the right place. Rather than just copying code, we'll build SimpleKafka incrementally, understanding each component as we go. This approach will give you a deep understanding of distributed messaging systems.
This incremental staged approach allows you to build and understand each component of a Kafka-like system starting from stage 1 to stage 7 in detail:
For Stages 1 through 7, follow the detailed step by step medium article while referencing the GitHub repository alongside it. This combination will help you progress through each section systematically.
By building each component yourself, you'll gain a deep understanding of Kafka's architecture and the design decisions behind it. This knowledge will be invaluable when working with the real Kafka or designing your own distributed systems.
mvn clean package# Start ZooKeeper with default configuration
zkServer start
# If that doesn't work, try:
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties
# Or create a simple config file:
echo "tickTime=2000" > zk.cfg
echo "dataDir=/tmp/zookeeper" >> zk.cfg
echo "clientPort=2181" >> zk.cfg
zookeeper-server-start zk.cfg# Terminal 1 - Broker 1
java -cp target/simple-kafka-1.0-SNAPSHOT.jar com.simplekafka.broker.SimpleKafkaBroker 1 localhost 9091 2181
# Terminal 2 - Broker 2
java -cp target/simple-kafka-1.0-SNAPSHOT.jar com.simplekafka.broker.SimpleKafkaBroker 2 localhost 9092 2181
# Terminal 3 - Broker 3
java -cp target/simple-kafka-1.0-SNAPSHOT.jar com.simplekafka.broker.SimpleKafkaBroker 3 localhost 9093 2181java -cp target/simple-kafka-1.0-SNAPSHOT.jar com.simplekafka.client.SimpleKafkaProducer localhost 9091 test-topicjava -cp target/simple-kafka-1.0-SNAPSHOT.jar com.simplekafka.client.SimpleKafkaConsumer localhost 9091 test-topic 0Watch how a topic gets divided into partitions and how those partitions are distributed across brokers.
暂无开放 Issues,或尚未同步最近议题。