gpt4 book ai didi

apache-kafka - 生产者如何找到 kafka 阅读器

转载 作者:行者123 更新时间:2023-12-03 16:40:57 24 4
gpt4 key购买 nike

生产者通过设置 Kafka Broker 列表来发送消息,如下所示。

props.put("bootstrap.servers", "127.0.0.1:9092,127.0.0.1:9092,127.0.0.1:9092");

我想知道“生产者”如何知道三个经纪人中的哪一个知道哪个有分区领导者。
对于典型的分布式服务器,要么你有一个承载服务器,要么有一个虚拟IP,但对于Kafka,它是如何加载的?
生产者程序是否尝试随机连接到一个代理并寻找具有分区领导者的代理?

最佳答案

一个 Kafka 集群包含多个代理实例。在任何给定时间,只有一个代理是领导者,而其余的是包含复制数据的同步副本 (ISR)。当 leader broker 被意外关闭时,ISR 之一将成为 leader。

Kafka 使用 ZooKeeper 选择一个 broker 分区的副本作为领导者。当生产者向主题中的分区发布消息时,它会被转发给其领导者。

根据 Kafka documentation :

The partitions of the log are distributed over the servers in the Kafka cluster with each server handling data and requests for a share of the partitions. Each partition is replicated across a configurable number of servers for fault tolerance.

Each partition has one server which acts as the "leader" and zero or more servers which act as "followers". The leader handles all read and write requests for the partition while the followers passively replicate the leader. If the leader fails, one of the followers will automatically become the new leader. Each server acts as a leader for some of its partitions and a follower for others so load is well balanced within the cluster.



您可以使用 this piece of code. 找到主题和分区领导者

编辑:

生产者向您在配置生产者时提供的其中一个代理发送带有主题列表的元请求。

来自代理的响应包含这些主题中的分区列表以及每个分区的领导者。生产者缓存此信息,因此,它知道将消息重定向到何处。

关于apache-kafka - 生产者如何找到 kafka 阅读器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49443397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com