删除所有消费者后,Kafka 消费者组会发生什么

What happens to a Kafka consumer group when all consumers are removed

我有一个带有自动缩放器的服务,每个实例都需要在一个单独的消费者组中,我通过随机创建一个消费者组名称来实现它 group-id: my-service-${random.uuid}。我想知道如果所有消费者都消失了,消费者群体会发生什么。我在 Confluent 平台上注意到我有很多消费者组,但没有任何消费者。

没有消费者的消费者组能存在多久?

如何配置要在删除服务后例如 5 分钟后删除的消费者组(我希望删除组而不仅仅是删除偏移量)?

在 Kafka 中,您在代理级别具有配置 offsets.retention.minutes

offsets.retention.minutes: After a consumer group loses all its consumers (i.e. becomes empty) its offsets will be kept for this retention period before getting discarded. For standalone consumers (using manual assignment), offsets will be expired after the time of last commit plus this retention period."

此配置默认为 7 天。查看 Broker Configurations 概览中的所有详细信息。

AdminClient 中还有一个 API 允许您删除特定的 ConsumerGroup。我已经在另一个 .

中用一些代码解释了这个过程

自 Confluent 6.x 以来,您还可以使用 confluent 控制中心(使用 REST API)轻松删除过时的 ConsumerGroups。