kafka的基本命令
1)查看当前服务器中的所有topic
[ kafka ]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 --list
2)创建topic
[ kafka ]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 --create --replication-factor 2 --partitions 1 --topic first
选项说明:
–topic 定义topic名
–replication-factor 定义副本数
–partitions 定义分区数
3)删除topic
[ kafka ]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 --delete --topic first
4)生产者消息
[ kafka ]$ bin/kafka-console-producer.sh --broker-list hadoop102:9092 --topic first
>hello world
>atguigu atguigu
5)消费消息
[ 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的详情
[ kafka ]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 --describe –-topic first
7)修改分区数
[ kafka ]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 --alter –-topic first --partitions 3