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

标签 apache-kafka

生产者通过设置 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/

相关文章:

python - 设置 Python KafkaProducer sasl 机制属性

azure - 将数据从 SQL Server 实时流式传输到 Azure 数据仓库

java - GlobalKTable - StreamsException : Encountered a topic-partition not associated with any global state store

java - 当我只想并发读取ConsumerRecords时,是否必须同步ConsumerRecords?

hadoop - FlumeData 文件未在 HDFS 接收器中创建

apache-kafka - 无法在 Centos 7/Centos 8 上启动 Kafka/Zookeeper 服务

docker - 设置connections.max.idle.ms不适用于使用Docker的Kafka Connect

java - Kafka在多节点集群中将主题存储在哪里?

hadoop - 如何在 hadoop 配置中使用亚马逊实例的公共(public) IP?

java - Kafka Streams 重新平衡高吞吐量 kafka-streams 服务上的延迟峰值