zoukankan      html  css  js  c++  java
  • Kafka: 下载安装和启动

    Step 1: 下载Kafka

    到官网下载后缀名为.tgz的文件,kafka_2.13-2.5.0.tgz,tgz是压缩文件,Windows需解压两次。

    Step 2: Start Zookeeper service

    启动kafka前需要先启动Zookeeper,CMD到kafka文件路径下

    • cd {KAFAK_HOME}

    # start zookeeper service (port: 2181)
    binwindowszookeeper-server-start.bat configzookeeper.properties

    Step 3: Start Kafka service

     再开另一个CMD窗口

    • cd {KAFAK_HOME}

    # start kafka broker serivce (port: 9092)
    binwindowskafka-server-start.bat configserver.properties

    Step 3: Create a Topic

     再开另一个CMD窗口,创建一个只有1个partition(分区)和1个replication-factor(备份),叫做test的topic

    • cd {KAFAK_HOME}

    # create a new kafka topic "test"
    binwindowskafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

     

     创建好之后,可以通过运行以下命令,查看已创建的topic信息:

    # list out all kafka topic
    binwindowskafka-topics.bat --list --zookeeper localhost:2181

     还可以用describe 命令查看更详细的topic信息

    # describe specific kafka topic "test"
    binwindowskafka-topics.bat --describe --zookeeper localhost:2181 --topic test

    Step 4: 发送消息和消费消息

    使用控制台producer 将数据发布到主题,同时打开两个命令窗口,一个运行生产者,一个运行消费者,这样就可以实时观察到发送和消费的动作。

    发送消息:

    # publish data to specific kafka topic "test"
    binwindowskafka-console-producer.bat --broker-list localhost:9092 --topic test

     

     消费消息:

    # subscribe specific kafka topic "test"
    binwindowskafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning

    还可以发送带有Key的value到topic

    发送消息:

    # publish data with key & value to specific kafka topic "test"
    binwindowskafka-console-producer.bat --broker-list localhost:9092 ^
    --topic test ^
    --property "parse.key=true" ^
    --property "key.separator=:"

     消费消息:

    # subscribe specific kafka topic "test" with key & value displayed
    binwindowskafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning --property print.key=true --property key.separator=":"

     有key的显示key值,之前发送没有key的显示nul

  • 相关阅读:
    11 数据的增删改
    10 外键的变种 三种关系
    09 完整性约束
    03 body标签中的相关标签
    02 body标签中的相关标签
    01 HTML介绍和head标签
    08 数据类型(2)
    07 数据类型
    06 表的操作
    偶遇RecyclerView内部Bug
  • 原文地址:https://www.cnblogs.com/fangjb/p/12912002.html
Copyright © 2011-2022 走看看