4、Kafka命令行操作

Kafka命令行操作

1)查看当前服务器中的所有topic

[test@ip101 kafka]$ bin/kafka-topics.sh --zookeeper ip101:2181 --list

2)创建topic

[test@ip101 kafka]$ bin/kafka-topics.sh --zookeeper ip101:2181 --create --replication-factor 3 --partitions 1 --topic first
选项说明:
--topic 定义topic名
--replication-factor 定义副本数
--partitions 定义分区数

3)删除topic

[test@ip101 kafka]$ bin/kafka-topics.sh --zookeeper ip101:2181 --delete --topic first
需要server.properties中设置delete.topic.enable=true否则只是标记删除或者直接重启。

4)发送消息

[test@ip101 kafka]$ bin/kafka-console-producer.sh --broker-list ip101:9092 --topic first

hello world
test test

5)消费消息

[test@ip102 kafka]$ bin/kafka-console-consumer.sh --zookeeper ip101:2181 --from-beginning --topic first
--from-beginning:会把first主题中以往所有的数据都读取出来。根据业务场景选择是否增加该配置。

6)查看某个Topic的详情

[test@ip101 kafka]$ bin/kafka-topics.sh --zookeeper ip101:2181 --describe --topic first

猜你喜欢

转载自www.cnblogs.com/xidianzxm/p/10711331.html