至少一个高可用性的 Kafka 概念

Kafka concept for high availability at-least-one

我已经阅读了一些关于 Kafka 的 How To 以及它如何与主题、生产者、消费者、消费者群体等一起工作,但不清楚你必须做什么才能实现不丢失消息,并且消费者群体中的消费者只阅读未提交的消息。所有的例子都是最简单的,它们没有给出任何指导

场景:

假设我有一个包含 4 个分区 P1-P4 的 TopicA。 我有 2 个属于消费者组 CG1 的消费者 C1 和 C2...当 coding/setting 向上 C1 和 C2 时我必须做什么,这样就不会丢失任何消息,即如果 C1 或 C2 crashes/restarts 他们应该开始读取来自 P1-P4 的未读消息(未提交),以便它们到达 Kafka。我是否必须配置 C1 和 C2 以了解 P1-P4,或者这是在幕后使用例如 confluent-kafka-dotnet 完成的?

谢谢!

当C1或C2崩溃(或重启)时,存活的消费者继续读取死亡消费者的分区,当消费者再次活跃时,分区再次重新平衡给消费者。

如果您的两个(或 N...所有!)消费者崩溃(或重新启动),当他们再次上线时,从他们离开的最后一点继续阅读,不会丢失或重复消息。

https://www.oreilly.com/library/view/kafka-the-definitive/9781491936153/ch04.html

Consumers in a consumer group share ownership of the partitions in the topics they subscribe to. When we add a new consumer to the group, it starts consuming messages from partitions previously consumed by another consumer. The same thing happens when a consumer shuts down or crashes; it leaves the group, and the partitions it used to consume will be consumed by one of the remaining consumers. Reassignment of partitions to consumers also happen when the topics the consumer group is consuming are modified (e.g., if an administrator adds new partitions).

https://medium.com/@jhansireddy007/how-to-parallelise-kafka-consumers-59c8b0bbc37a

Q. What if consumer-B goes down? A. Kafka will do rebalancing and it would assign all the four partitions to consumer-A.

if C1 or C2 crashes/restarts they should start read unread messages

当消费者崩溃并重新启动时,它将从上次读取的偏移量开始读取,所以是的,它只会读取未提交的消息。

(uncomitted) from P1-P4 in order they arrived to Kafka

在一个主题中使用多个分区时还需要考虑的一件事是消息可能不会按顺序使用。

您可以在此处阅读更多相关信息:link

Do I have to configure C1 and C2 to know about P1-P4 or is this done under the hood

我们不需要为分区配置消费者。它在幕后很小心,它试图重新平衡消费者组中所有消费者的分区。如果需要,我们还可以将特定分区分配给主题。

更多信息:link