zoukankan      html  css  js  c++  java
  • kafka命令行入门

    Kafka命令行操作入门

    Topics

    1、查看所有的topics

    bin/kafka-topics.sh --zookeeper localhost:2181 --list
    

    2、创建topics

    bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic myTopic --partitions 2 --replication-factor 1
    
    • create:表示创建
    • topic:后面接上要操作的主题的名字
    • partitions:表示创建的分区个数
    • replication-factor:副本数,注意,副本数不能大于brokers的数量

    创建成功之后会在配置文件server.properties制定的log.dirs目录下创建#{topic_name}-%d形式的分区的文件夹

    3、删除主题

    bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic myTopic
    

    4、查看主题详情

    bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic myTopic
    

    注意,查看的主题必须存在,否则会报错

    Topic: myTopic	PartitionCount: 2	ReplicationFactor: 1	Configs: 
    	Topic: myTopic	Partition: 0	Leader: 0	Replicas: 0	Isr: 0
    	Topic: myTopic	Partition: 1	Leader: 0	Replicas: 0	Isr: 0
    

    生产者和消费者

    开启生产者

    bin/kafka-console-producer.sh --topic myTopic --broker-list localhost:9092
    

    开启消费者

    bin/kafka-console-consumer.sh --topic myTopic --bootstrap-server localhost:9092
    

    直接在生产者的那端输入,消费者就可以接受到

    消费者从头开始消费

    bin/kafka-console-consumer.sh --topic myTopic --bootstrap-server localhost:9092 --from-beginning
    

    一般用于不在线的消费者重新上线用,但是kafka默认的保留时间为7天,如果不修改配置文件,则消费不到7天之前的数据。

  • 相关阅读:
    复习列表
    20201009 day30 复习2:滑动窗口
    20201009 day30 复习1:扫描线
    20201007day29 模拟(九)
    20201006day28 模拟(八)
    20201005day27 模拟(七)
    20201004 day26 模拟(六)
    20201003day25 模拟(五)
    路由重分布(一)
    RIP路由协议(一)
  • 原文地址:https://www.cnblogs.com/ivy-blogs/p/14061523.html
Copyright © 2011-2022 走看看