简体   繁体   English

如何自动删除未使用的kafka用户

[英]how to automatically delete unused kafka consumers

I am using Kafka for a messaging application. 我正在将Kafka用于消息传递应用程序。 For this application, there is a producer putting messages into a topic, and consumers registered to this topic, and consuming these messages. 对于此应用程序,有一个生产者将消息放入一个主题中,而消费者将其注册到该主题中并使用这些消息。 These consumers are Dockerized applications. 这些使用者是Dockerized应用程序。 For autoscaling purposes, each consumer, upon its creation, is registered as a consumer with a unique ID. 出于自动缩放的目的,每个使用者在创建时都被注册为具有唯一ID的使用者。

Assume the following scenario: 假定以下情况:

Consumer1 is created as a docker container, and registers itself as a consumer with ID Consumer1 Consumer1被创建为Docker容器,并使用ID Consumer1注册为Consumer1

Consumer2 is created as a docker container, and registers itself as a consumer with ID Consumer2 Consumer2被创建为docker容器,并使用ID Consumer2注册为Consumer2

Now for whatever reason Consumer1 fails, and gets replaced by Consumer3 which registers itself as a consumer to kafka with an ID of Consumer3 . 现在,无论出于何种原因, Consumer1都会失败,并被Consumer3取代,后者将自己作为ID为Consumer3 kafka的Consumer3

The problem is, Consumer1 is no longer used. 问题是,不再使用Consumer1 On the long term, there will be multiple unused consumers. 从长远来看,将有多个未使用的消费者。

Is there a way to dynamically and automatically know which consumers are no longer used and delete them? 有没有办法动态地自动知道哪些使用者不再使用并删除它们?

If consumer1 and consumer3 belongs to the same consumer group, consumer3 will start reading messages from where consumer1 left off. 如果消费者1和消费者3属于同一消费者组,那么消费者3将开始从消费者1停止的地方读取消息。 This is because Kafka maintains the offset specific to a consumer group. 这是因为Kafka维护特定于消费者组的偏移量。 So in case one among the consumers with same consumer group fails, others will use the offset and avoid reprocessing the data. 因此,如果具有相同消费者组的消费者中的一个失败,则其他消费者将使用偏移量并避免重新处理数据。

Kafka broker does not maintain the failed consumers log anywhere as you assume in your question. Kafka经纪人不会像您在问题中所假设的那样维护失败的使用者日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM