1.查看当前服务器所有的topic
[atguigu@hadoop102 kafka]$ bin/kafka-topic.sh --zookeeper hadoop102:2181/kafka --list
2.创建topic
[atguigu@hadoop102 kafka]$ bin/kafka-topic.sh --zookeeper hadoop102:2181/kafka --create --replication-factor 3 --partitons 1 --topic first
---topic 定义topic名
--- replication-factor 定义副本数
--- partitions定义分区数
3.删除topic
[atguigu@hadoop102 kafka]$ bin/kafka-topic.sh --zookeeper hadoop102:2181/kafka --delete --topic first
4.发送消息
[atguigu@hadoop102 kafka]$ bin/kafka-console-producer.sh --broker-list hadoop102:9092 --topic first
>hello world
>atguigu
/// brokers-list 必传参数 用来指定kafka的代理地址多个用逗号分割
// topic 必传参数 用来指定所发送的目标主题
5.消费者
[atguigu@hadoop102 kafka]$ bin/kafka-console-consumer.sh --bootstrap-server hadoop102:9092 --from-beginning --topic first
6.查看某个Topic的详情
[atguigu@hadoop102 kafka]$ bin/kafka-topic.sh --zookeeper hadoop102:2181/kafka --describe --topic first
7.查看kafka的活动brokers ids
cd 到kafka的目录
bin/zookeeper-shell.sh hadoop102:2181,hadoop103:2181,hadoop104:2181
ls /kafka/brokers/ids // [0,1,2] 活动的brokers的id
网友评论