kafka常用命令行操作

  1. 查看当前服务器中所有的topic
bin/kafka-topics.sh --zookeeper hostname:2181 --list
  1. 创建topic
bin/kafka-topics.sh --zookeeper hostname:2181 --create --replication-factor 3 --partitions 1 --topic first
  • 说明:
  • –topic 定义topic名
  • –replication-factor 定义副本数
  • –partitions 定义分区数,且分区数不能大于服务器数目
  1. 删除topic
bin/kafka-topics.sh --zookeeper hostname:2181 --delete --topic first
  • 注:需要在server.properties中设置delete.topic.enable=true,否则只是标记删除或者直接重启
  1. 发送消息
bin/kafka-console-producer.sh --broker-list hostname:9092 --topic first
>hello
>hi
  1. 消费消息
bin/kafka-console-consumer.sh --zookeeper hostname:2181 --from-beginning --topic first
  • 注:–from-beginning 会把first主题中以往所有的数据都读取出来,可根据个人需要选择是否增加该配置
  1. 查看某个topic的详情
bin/kafka-topics.sh --zookeeper hostname:2181 --describe --topic first

猜你喜欢

转载自blog.csdn.net/qq_41725214/article/details/86769539
今日推荐