apache-kafka - Kafka 单个消费者在一个组中失败

标签 apache-kafka

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

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

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

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

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

    最佳答案

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

    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


    同一组中的另一个实时消费者将在超时间隔后开始接收消息。
    根据您的要求配置此超时值。
    还有一些来自 kafka 文档的更多信息:

    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. If your consumer subscribes to many topics and your ZK server is busy, this could be caused by consumers not having enough time to see a consistent view of all consumers in the same group. If this is the case, try Increasing rebalance.max.retries and rebalance.backoff.ms.
    2. Another reason could be that one of the consumers is hard killed. Other consumers during rebalancing won't realize that consumer is gone after zookeeper.session.timeout.ms time. In the case, make sure that rebalance.max.retries * rebalance.backoff.ms > zookeeper.session.timeout.ms.

    关于apache-kafka - Kafka 单个消费者在一个组中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23775087/

    相关文章:

    apache-kafka - Kafka 在尝试访问磁盘上的日志文件时抛出异常磁盘错误

    apache-kafka - Flink 检查点不断失败(等待 InitProducerId 时超时)

    docker - 无法从NiFi发送到Kafka

    apache-spark - 即使将 "auto.offset.reset"设置为 "latest"后也会出现错误 OffsetOutOfRangeException

    java - 获取没有客户端 ID 的 kafka 主题指标

    hadoop - 多个服务可以使用同一个 Zookeeper 实例吗?

    java - 如何在 Spring Cloud Stream 的事务上下文中使用 MessageChannel?

    apache-storm - 在尊重 maxSpoutPending 的同时关闭 KafkaSpout 中的 acking

    apache-storm - Kafka Storm spout 改变拓扑并从旧偏移量中消费

    java - 使用kafka流根据消息 key 向主题发送消息