日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

转载-zookeeper在kafka中的作用

發布時間:2025/3/15 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 转载-zookeeper在kafka中的作用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

1)Broker注冊

  Broker在zookeeper中保存為一個臨時節點,節點的路徑是/brokers/ids/[brokerid],每個節點會保存對應broker的IP以及端口等信息.

  2)Topic注冊

  在kafka中,一個topic會被分成多個區并被分到多個broker上,分區的信息以及broker的分布情況都保存在zookeeper中,根節點路徑為/brokers/topics,每個topic都會在topics下建立獨立的子節點,每個topic節點下都會包含分區以及broker的對應信息,例如下圖中的狀態

  3)生產者負載均衡

  當Broker啟動時,會注冊該Broker的信息,以及可訂閱的topic信息。生產者通過注冊在Broker以及Topic上的watcher動態的感知Broker以及Topic的分區情況,從而將Topic的分區動態的分配到broker上.

  4)消費者

  kafka有消費者分組的概念,每個分組中可以包含多個消費者,每條消息只會發給分組中的一個消費者,且每個分組之間是相互獨立互不影響的。

  5)消費者與分區的對應關系

  對于每個消費者分組,kafka都會為其分配一個全局唯一的Group ID,分組內的所有消費者會共享該ID,kafka還會為每個消費者分配一個consumer ID,通常采用hostname:uuid的形式。在kafka的設計中規定,對于topic的每個分區,最多只能被一個消費者進行消費,也就是消費者與分區的關系是一對多的關系。消費者與分區的關系也被存儲在zookeeper中節點的路勁為 /consumers/[group_id]/owners/[topic]/[broker_id-partition_id],該節點的內容就是消費者的Consumer ID

  6)消費者負載均衡

  消費者服務啟動時,會創建一個屬于消費者節點的臨時節點,節點的路徑為 /consumers/[group_id]/ids/[consumer_id],該節點的內容是該消費者訂閱的Topic信息。每個消費者會對/consumers/[group_id]/ids節點注冊Watcher監聽器,一旦消費者的數量增加或減少就會觸發消費者的負載均衡。消費者還會對/brokers/ids/[brokerid]節點進行監聽,如果發現服務器的Broker服務器列表發生變化,也會進行消費者的負載均衡

  7)消費者的offset

  在kafka的消費者API分為兩種(1)High Level Api:由zookeeper維護消費者的offset (2) Low Level API,自己的代碼實現對offset的維護。由于自己維護offset往往比較復雜,所以多數情況下都是使用High Level的APIoffset在zookeeper中的節點路徑為/consumers/[group_id]/offsets/[topic]/[broker_id-part_id],該節點的值就是對應的offset

  二、kakfa在zookeeper中的結構

  

 kafka.javaapi.consumer.ZookeeperConsumerConnector.java

  /**

  * This class handles the consumers interaction with zookeeper

  *

  * Directories:

  * 1. Consumer id registry:

  * /consumers/[group_id]/ids[consumer_id] -> topic1,...topicN

  * A consumer has a unique consumer id within a consumer group. A consumer registers its id as an ephemeral znode

  * and puts all topics that it subscribes to as the value of the znode. The znode is deleted when the client is gone.

  * A consumer subscribes to event changes of the consumer id registry within its group.

  *

  * The consumer id is picked up from configuration, instead of the sequential id assigned by ZK. Generated sequential

  * ids are hard to recover during temporary connection loss to ZK, since it's difficult for the client to figure out

  * whether the creation of a sequential znode has succeeded or not. More details can be found at

  *

  *?2. Broker node registry:

  * /brokers/[0...N] --> { "host" : "host:port",

  * "topics" : {"topic1": ["partition1" ... "partitionN"], ...,

  * "topicN": ["partition1" ... "partitionN"] } }

  * This is a list of all present broker brokers. A unique logical node id is configured on each broker node. A broker

  * node registers itself on start-up and creates a znode with the logical node id under /brokers. The value of the znode

  * is a JSON String that contains (1) the host name and the port the broker is listening to, (2) a list of topics that

  * the broker serves, (3) a list of logical partitions assigned to each topic on the broker.

  * A consumer subscribes to event changes of the broker node registry.

  *

  * 3. Partition owner registry:

  * /consumers/[group_id]/owner/[topic]/[broker_id-partition_id] --> consumer_node_id

  * This stores the mapping before broker partitions and consumers. Each partition is owned by a unique consumer

  * within a consumer group. The mapping is reestablished after each rebalancing.

  *

  *?4. Consumer offset tracking:

  * /consumers/[group_id]/offsets/[topic]/[broker_id-partition_id] --> offset_counter_value

  * Each consumer tracks the offset of the latest message consumed for each partition.

  *

  */

歡迎工作一到五年的Java工程師朋友們加入Java架構開發:855801563

群內提供免費的Java架構學習資料(里面有高可用、高并發、高性能及分布式、Jvm性能調優、Spring源碼,MyBatis,Netty,Redis,Kafka,Mysql,Zookeeper,Tomcat,Docker,Dubbo,Nginx等多個知識點的架構資料)合理利用自己每一分每一秒的時間來學習提升自己,不要再用"沒有時間“來掩飾自己思想上的懶惰!趁年輕,使勁拼,給未來的自己一個交代

轉載于:https://my.oschina.net/u/3959491/blog/2252432

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的转载-zookeeper在kafka中的作用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。