-
开启进程:
./bin/kafka-server-start.sh config/server.properties
-
查看topic列表:
./bin/kafka-topics.sh --list --zookeeper localhost:2181
-
创建topic:
./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic zhongqiu_test
-
查看topic描述:
./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic zhongqiu_test
-
producer发送信息:
./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic zhongqiu_test
-
consumer接收信息:
./bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic zhongqiu_test --from-beginning
-
删除topic:
./bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic zhongqiu_test
集群版
-
分别设置slave1、slave2两个节点的server.properties配置中的broker.id分别为1和2
-
创建topic:
./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 5 --topic zhongqiu_many_brokers
-
下面的命令会创建失败,原因是副本数大于实际broker个数
./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 4 --partitions 5 --topic zhongqiu_many_brokers_4reps
-
查看topic描述:
./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic zhongqiu_many_brokers
# 执行结果
Topic:zhongqiu_many_brokers PartitionCount:5 ReplicationFactor:3 Configs:
Topic: zhongqiu_many_brokers Partition: 0 Leader: 2 Replicas: 2,1,0 Isr: 0,1,2
Topic: zhongqiu_many_brokers Partition: 1 Leader: 0 Replicas: 0,2,1 Isr: 0,1,2
Topic: zhongqiu_many_brokers Partition: 2 Leader: 1 Replicas: 1,0,2 Isr: 0,1,2
Topic: zhongqiu_many_brokers Partition: 3 Leader: 2 Replicas: 2,0,1 Isr: 0,1,2
Topic: zhongqiu_many_brokers Partition: 4 Leader: 0 Replicas: 0,1,2 Isr: 0,1,2