Kafka 单个消费者在一个组中失败 [英] Kafka single consumer failure in a group

查看:41
本文介绍了Kafka 单个消费者在一个组中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正处于探索 Kafka 0.8.1.1 版本的初始阶段.

I am in the initial phases of exploring Kafka, version 0.8.1.1.

我已经成功运行了具有多个分区的消费者组示例,并且它在消费者之间很好地分发了消息.

I've successfully run the Consumer Group Example, with multiple partitions and its distributing messages among the consumers quite well.

我想运行的一个测试用例是当组中的一个消费者突然死亡时(例如, kill -9 ).当我这样做时,我预计会发生重新平衡,但它没有发生.那么,我可以做其中一件事情吗?

One test case I wanted to run is when a consumer in the group dies suddenly (example, kill -9 ). When I do so, I expected rebalancing to occur, but its not happening. So, can I do one of these things?

  1. 使用 API 触发重新平衡
  2. 将 kafka 配置为等待消费者活动的特定时间,并在假设它不正常关闭时自动重新平衡.

这里的问题是,分配给死消费者的分区中的所有消息都保留在队列中,并且在重新平衡发生之前永远不会被处理.

The problem here is, all the messages in the partitions assigned to the dead Consumer remains in the queue and is never processed until rebalancing occurs.

推荐答案

重新平衡将自动发生,可以在消费者配置 (zookeeper.session.timeout.ms) 中设置.根据文档

The Rebalance will happen automatically which can be set in the consumer config ( zookeeper.session.timeout.ms ). As per the documentaion

zookeeper.session.timeout.ms :ZooKeeper 会话超时.如果消费者在这段时间内未能向 zookeeper 发出心跳,则认为它已死亡,并会发生重新平衡.默认值为 6000 毫秒

zookeeper.session.timeout.ms : ZooKeeper session timeout. If the consumer fails to heartbeat to zookeeper for this period of time it is considered dead and a rebalance will occur. default value is 6000 ms

同一组中的其他实时消费者将在超时间隔后开始接收消息.

The other live consumer in the same group will start to recieve the message after the timeout interval.

根据您的要求配置此超时值.

Configure this timeout value as per your requirements.

还有一些来自 kafka 文档的更多信息:

Also some more info from the kafka documentation:

消费者重新平衡失败(您将看到 ConsumerRebalanceFailedException):这是由于当两个消费者试图拥有同一个主题分区时发生冲突.日志将显示导致冲突的原因(搜索conflict in").

Consumer rebalancing fails (you will see ConsumerRebalanceFailedException): This is due to conflicts when two consumers are trying to own the same topic partition. The log will show you what caused the conflict (search for "conflict in ").

  1. 如果您的消费者订阅了很多主题,而您的 ZK 服务器很忙,这可能是因为消费者没有足够的时间查看同一组中所有消费者的一致视图.如果是这种情况,请尝试增加 rebalance.max.retries 和 rebalance.backoff.ms.
  2. 另一个原因可能是其中一位消费者被杀.其他消费者在重新平衡期间不会意识到消费者在 zookeeper.session.timeout.ms 时间后消失了.在这种情况下,请确保 rebalance.max.retries * rebalance.backoff.ms >zookeeper.session.timeout.ms.

这篇关于Kafka 单个消费者在一个组中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆