kafka消费不到数据的排查过程

 更新时间:2023年02月08日 16:42:24   作者:香山上的麻雀1008  
这篇文章主要介绍了kafka消费不到数据的排查过程,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

kafka消费不到数据的排查

集群上新安装并启动了3个kafka Broker,代码打包上传至集群,运行后发现一直消费不到数据,

本地idea中debug后发现,程序一直阻塞在如下程序中,陷入了死循环。

  /**
     * Block until the coordinator for this group is known and is ready to receive requests.
     * 等待直到我们和服务端的GroupCoordinator取得连接
     */
    public void ensureCoordinatorReady() {
        while (coordinatorUnknown()) {//无法获取GroupCoordinator
            RequestFuture<Void> future = sendGroupCoordinatorRequest();//发送请求
            client.poll(future);//同步等待异步调用的结果
            if (future.failed()) {
                if (future.isRetriable())
                    client.awaitMetadataUpdate();
                else
                    throw future.exception();
            } else if (coordinator != null && client.connectionFailed(coordinator)) {
                // we found the coordinator, but the connection has failed, so mark
                // it dead and backoff before retrying discovery
                coordinatorDead();
                time.sleep(retryBackoffMs);//等待一段时间,然后重试
            }

        }
    }

流程大概说就是

  • consumer会从集群中选取一个broker作为coordinator
  • 然后group中的consumer会向coordinator发请求申请成为consumergroup中的leader
  • 最后有1个consumer会成为consumerLeader ,其他consumer成为follower
  • consumerLeader做分区分配任务,同步给coordinator
  • consumerFollower从coordinator同步分区分配数据

问题出现在第一步,意思就是说Consumer和服务端的GroupCoordinator无法取得连接,所以程序一直在等待状态。

看了下__consumer_offsets 这个topic情况,50个分区全在broker id为152的broker上

bin/kafka-topics.sh --describe --zookeeper localhost:2182 --topic __consumer_offsets
Topic:__consumer_offsets    PartitionCount:50    ReplicationFactor:1    Configs:segment.bytes=104857600,cleanup.policy=compact,compression.type=producer
    Topic: __consumer_offsets    Partition: 0    Leader: 152    Replicas: 152   Isr:152
    Topic: __consumer_offsets    Partition: 1    Leader: 152    Replicas: 152   Isr:152
    Topic: __consumer_offsets    Partition: 2    Leader: 152    Replicas: 152   Isr:152
    Topic: __consumer_offsets    Partition: 3    Leader: 152   
......

但是集群上并没有broker id为152的节点,想到该集群kafka节点曾经添加删除过节点,初步断定152是之前的kafka节点,后来该节点去掉后又加入新的节点但是zookeeper中的数据并没有更新。

所以就关闭broker,进入zookeeper客户端,将brokers节点下的topics节点下的__consumer_offsets删除,然后重启broker,注意,此时zookeeper上__consumer_offsets还并没有生成,要开启消费者之后才会生成.

然后再观察__consumer_offsets,分区已经均匀分布在三个broker上面了

 bin/kafka-topics.sh --zookeeper localhost:2182 --describe --topic __consumer_offsets
Topic:__consumer_offsets    PartitionCount:50    ReplicationFactor:3    Configs:segment.bytes=104857600,cleanup.policy=compact,compression.type=producer
    Topic: __consumer_offsets    Partition: 0    Leader: 420    Replicas: 420,421,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 1    Leader: 421    Replicas: 421,422,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 2    Leader: 422    Replicas: 422,420,421    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 3    Leader: 420    Replicas: 420,422,421    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 4    Leader: 421    Replicas: 421,420,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 5    Leader: 422    Replicas: 422,421,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 6    Leader: 420    Replicas: 420,421,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 7    Leader: 421    Replicas: 421,422,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 8    Leader: 422    Replicas: 422,420,421    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 9    Leader: 420    Replicas: 420,422,421    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 10    Leader: 421    Replicas: 421,420,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 11    Leader: 422    Replicas: 422,421,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 12    Leader: 420    Replicas: 420,421,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 13    Leader: 421    Replicas: 421,422,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 14    Leader: 422    Replicas: 422,420,421    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 15    Leader: 420    Replicas: 420,422,421    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 16    Leader: 421    Replicas: 421,420,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 17    Leader: 422    Replicas: 422,421,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 18    Leader: 420    Replicas: 420,421,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 19    Leader: 421    Replicas: 421,422,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 20    Leader: 422    Replicas: 422,420,421    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 21    Leader: 420    Replicas: 420,422,421    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 22    Leader: 421    Replicas: 421,420,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 23    Leader: 422    Replicas: 422,421,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 24    Leader: 420    Replicas: 420,421,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 25    Leader: 421    Replicas: 421,422,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 26    Leader: 422    Replicas: 422,420,421    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 27    Leader: 420    Replicas: 420,422,421    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 28    Leader: 421    Replicas: 421,420,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 29    Leader: 422    Replicas: 422,421,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 30    Leader: 420    Replicas: 420,421,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 31    Leader: 421    Replicas: 421,422,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 32    Leader: 422    Replicas: 422,420,421    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 33    Leader: 420    Replicas: 420,422,421    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 34    Leader: 421    Replicas: 421,420,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 35    Leader: 422    Replicas: 422,421,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 36    Leader: 420    Replicas: 420,421,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 37    Leader: 421    Replicas: 421,422,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 38    Leader: 422    Replicas: 422,420,421    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 39    Leader: 420    Replicas: 420,422,421    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 40    Leader: 421    Replicas: 421,420,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 41    Leader: 422    Replicas: 422,421,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 42    Leader: 420    Replicas: 420,421,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 43    Leader: 421    Replicas: 421,422,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 44    Leader: 422    Replicas: 422,420,421    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 45    Leader: 420    Replicas: 420,422,421    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 46    Leader: 421    Replicas: 421,420,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 47    Leader: 422    Replicas: 422,421,420    Isr: 422,420,421
    Topic: __consumer_offsets    Partition: 48    Leader: 420    Replicas: 420,421,422    Isr: 420,422,421
    Topic: __consumer_offsets    Partition: 49    Leader: 421    Replicas: 421,422,420    Isr: 422,420,421

这个时候重启程序,发现已经可以正常消费了,问题解决。

参考资料:

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • SpringBoot全局异常捕获处理实现方案

    SpringBoot全局异常捕获处理实现方案

    这篇文章主要详细介绍了SpringBoot全局异常捕获处理实现方案,文章通过代码示例给大家介绍的非常详细,对大家的学习或工作有一定的帮助,需要的朋友可以参考下
    2024-02-02
  • Java.try catch finally 的执行顺序说明

    Java.try catch finally 的执行顺序说明

    这篇文章主要介绍了Java.try catch finally 的执行顺序说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-10-10
  • 最大子数组和Java实现代码示例

    最大子数组和Java实现代码示例

    这篇文章主要介绍了最大子数组和Java实现的相关资料,文中介绍了两种方法来解决寻找具有最大和的连续子数组的问题,第一种方法是动态规划,第二种方法是分治法,需要的朋友可以参考下
    2024-11-11
  • 你必须得会的SpringBoot全局统一处理异常详解

    你必须得会的SpringBoot全局统一处理异常详解

    程序在运行的过程中,不可避免会产生各种各样的错误,这个时候就需要进行异常处理,本文主要为大家介绍了SpringBoot实现全局统一处理异常的方法,需要的可以参考一下
    2023-06-06
  • 基于Java+SpringBoot+Vue前后端分离实现仓库管理系统

    基于Java+SpringBoot+Vue前后端分离实现仓库管理系统

    这篇文章主要介绍了一个完整的仓库管理系统是基于Java+Springboot + Vue前后端分离编写的,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-06-06
  • 解决springboot导入失败,yml未识别的问题

    解决springboot导入失败,yml未识别的问题

    这篇文章主要介绍了解决springboot导入失败,yml未识别的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-07-07
  • Java中Map接口使用以及有关集合的面试知识点汇总

    Java中Map接口使用以及有关集合的面试知识点汇总

    在java面试过程中,Map时常会被作为一个面试点来问,下面这篇文章主要给大家介绍了关于Java中Map接口使用以及有关集合的面试知识点汇总的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-07-07
  • MyBatisPlus3如何向数据库中存入List

    MyBatisPlus3如何向数据库中存入List

    本文主要介绍了Mybatis Plus的类型处理器的使用,通过User.java和UserMapper.xml示例进行详细的解析,并提供了JSON解析器的使用方法,希望通过这篇文章,可以帮助大家更好的理解和掌握Mybatis Plus的类型处理器
    2024-10-10
  • Java 8新特性 内建函数式接口详解

    Java 8新特性 内建函数式接口详解

    这篇文章主要介绍了Java 8新特性 内建函数式接口详解的相关资料,这里主要介绍4个基本函数式接口,需要的朋友可以参考下
    2016-12-12
  • 自定义log4j.properties的加载位置方式

    自定义log4j.properties的加载位置方式

    这篇文章主要介绍了自定义log4j.properties的加载位置方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-12-12

最新评论