zoukankan      html  css  js  c++  java
  • kafaka学习

    创建一个topic:

    [root@hdp1 bin]# ./kafka-topics.sh --create --zookeeper hdp1:2181  --replication-factor 1 --partitions 1 --topic justin
    Created topic "justin".
    [root@hdp1 bin]# pwd
    /usr/hdp/2.2.6.0-2800/kafka/bin

    在zookeeper中可以查看到刚才创建的topic:

    [zk: hdp1:2181(CONNECTED) 4] ls /brokers/topics
    [topic1, ambari_kafka_service_check, justin, test, kafkaToptic]

    由于在创建topic的时候,指定—partitions为1,所有在zookeeper中看到的分区数为一个:

    [zk: hdp1:2181(CONNECTED) 7] ls /brokers/topics/justin/partitions
    [0]
    [zk: hdp1:2181(CONNECTED) 8] ls /brokers/topics/justin/partitions/0
    [state]
    [zk: hdp1:2181(CONNECTED) 9] ls /brokers/topics/justin/partitions/0/state
    []
    [zk: hdp1:2181(CONNECTED) 10] ls /brokers/topics/justin/partitions/0      
    [state]
    [zk: hdp1:2181(CONNECTED) 11] ls /brokers/topics/justin/partitions/0/state
    []

    kafka自带脚本也可以查看到zookeeper中创建的topic:

    [root@hdp1 bin]# ./kafka-topics.sh --list --zookeeper hdp1:2181
    ambari_kafka_service_check
    justin
    kafkaToptic
    test
    topic1

    使用生产者,往kafka队列的justin主题(类似于bigpipe的pipe,partition和bigpipe的pipelet类似)发送两条消息:

    [root@hdp1 bin]# ./kafka-console-producer.sh --broker-list hdp1:6667 --topic justin
    justinzhang
    This is another justin

    使用消费者,从kafka队列的topic中获取消息,—from-beginning表示从开始处订阅:

    [root@hdp1 bin]# ./kafka-console-consumer.sh --zookeeper hdp1:2181 --topic justin --from-beginning
    justinzhang
    This is another justin

    可以使用将标准输入定位到文件的方式,往broker发送文件:

    [root@hdp1 bin]# ./kafka-console-producer.sh --broker-list hdp1:6667 --topic justin < kafka-server-stop.sh

    多个订阅者都可以收到生产者发送的消息。

  • 相关阅读:
    Intel CPU编号详解
    matplotlib(二)——matplotlib控制坐标轴第一个刻度到原点距离
    matplotlib(一)——matplotlib横轴坐标密集字符覆盖
    博客园定制页面(五)——使用自定义JS脚本(公告栏显示时间)
    PyCharm(二)——PyCharm打开本地项目不显示项目文件
    nohup命令
    URL是如何解析的
    Python 得到主机字节序
    Python 得到ISP地址
    亚马逊s3上传大文件Python
  • 原文地址:https://www.cnblogs.com/justinzhang/p/4647586.html
Copyright © 2011-2022 走看看