1)查看当前服务器中的所有topic
[atguigu@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper
hadoop102:2181 --list
2)创建topic
[atguigu@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper
hadoop102:2181 --create --replication-factor 3 --partitions 1
--topic first
选项说明:
–topic 定义topic名
–replication-factor 定义副本数
–partitions 定义分区数
3)删除topic
[atguigu@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper
hadoop102:2181 --delete --topic first
4)发送消息
[atguigu@hadoop102 kafka]$ bin/kafka-console-producer.sh
--broker-list hadoop102:9092 --topic first
hello world
atguigu atguigu
5)消费消息
[atguigu@hadoop102 kafka]$ bin/kafka-console-consumer.sh \
--bootstrap-server hadoop102:9092 --topic first
[atguigu@hadoop102 kafka]$ bin/kafka-console-consumer.sh \
--bootstrap-server hadoop102:9092 --from-beginning --topic first
–from-beginning:会把主题中现有的所有的数据都读取出来。
6)查看某个Topic的详情
[atguigu@hadoop102 kafka]$ bin/kafka-topics.sh
--zookeeper hadoop102:2181 --describe –
-topic first
7)修改分区数
[atguigu@hadoop102 kafka]$ bin/kafka-topics.sh
--zookeeper hadoop102:2181 --alter –-
topic first --partitions 6