美文网首页
kafka常用命令

kafka常用命令

作者: chen_666 | 来源:发表于2020-04-25 18:23 被阅读0次

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

     [root@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 --list
    

    2)创建 topic

     [root@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 \
    --create --replication-factor 3 --partitions 1 --topic first
    

    选项说明:
    --topic 定义 topic 名
    --replication-factor 定义副本数
    --partitions 定义分区数

    3)删除 topic

     [root@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 \
    --delete --topic first
    

    需要 server.properties 中设置 delete.topic.enable=true 否则只是标记删除或者直接重启。
    4)发送消息

     [root@hadoop102 kafka]$ bin/kafka-console-producer.sh \
    --broker-list hadoop102:9092 --topic first
    >hello world
    >atguigu atguigu
    

    5)消费消息

     [root@hadoop102 kafka]$ bin/kafka-console-consumer.sh \
    --zookeeper hadoop102:2181 --from-beginning --topic first
    

    6)查看某个Topic 的详情

     [root@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 \
    --describe --topic first
    

    相关文章

      网友评论

          本文标题:kafka常用命令

          本文链接:https://www.haomeiwen.com/subject/hywkwhtx.html