启动 zookeeper
./bin/zookeeper-server-start.sh -daemon ./config/zookeeper.properties
关闭 zookeeper
./bin/zookeeper-server-stop.sh -daemon ./config/zookeeper.properties
启动 kafka
./bin/kafka-server-start.sh -daemon ./config/server.properties
停止 kafka
./bin/kafka-server-stop.sh ./config/server.properties
创建 topic
./bin/kafka-topics.sh --create --zookeeper localhost:2181/kafka --replication-factor 1 --partitions 1 --topic test
Created topic test.
查看 topic
./bin/kafka-topics.sh --list --zookeeper localhost:2181/kafka
test
发送消息
./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
接收消息
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
./bin/kafka-topics.sh --zookeeper localhost:2181/kafka --describe --topic test
Topic: test PartitionCount: 1 ReplicationFactor: 1 Configs:
Topic: test Partition: 0 Leader: 0 Replicas: 0 Isr: 0
./bin/kafka-topics.sh --zookeeper localhost:2181/kafka --delete --topic test
Topic test is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.
idea 调试 kafka 源码
- git clone https://github.com/apache/kafka.git
- 进入kafka目录执行:./gradlew build
- 使用idea打开 kafka 源码目录
- 将 kafka/config/log4j.properties copy 到 /kafka/core/src/main/resources
- project(’:core’) dependencies 增加 implementation libs.slf4jlog4j 否则找不到 SLF4J