简体   繁体   English

在Java代码中检查Kafka消费者组的活跃性

[英]Checking Kafka consumer group liveliness in java code

I have written a java code for Kafka consumer using executor service which will run 24/7 consume the data and process it. 我已经使用执行程序服务为Kafka消费者编写了Java代码,该服务将以24/7的速度运行并使用数据并对其进行处理。

But in some scenarios like due to Kafka coordinator broker node went down, job will fail ie, consumer group will become dead and i will not able to know it and the java jar would be running but not doing anything. 但是在某些情况下,例如由于Kafka协调器代理节点发生故障,工作将失败,即,消费者组将死掉,而我将不知道它,并且Java jar将运行但不执行任何操作。

 INFO [2018-11-07 03:25:58,425] [pool-1-thread-1] (AbstractCoordinator.java:coordinatorDead) - Marking the coordinator broker_host (id: 2147483446 rack: null) dead for group group_name
 INFO [2018-11-07 03:26:10,817] [pool-1-thread-1] (AbstractCoordinator.java:onSuccess) - Discovered coordinator broker_host (id: 2147483446 rack: null) for group group_name.

I want to check the Kafka consumer liveliness in java code periodically. 我想定期检查Java代码中的Kafka消费者活动情况。 So, if Kafka consumer group becomes dead, i will be able to make it live or trigger the mail and kill the job. 因此,如果卡夫卡消费群体死亡,我将能够使其生存或触发邮件并杀死工作。

Can anyone provide any input on this. 任何人都可以对此提供任何输入。

If the broker acting as coordinator for your consumer group goes down, each consumer in the group will find which remaining broker is to become the new coordinator for their group. 如果充当您的消费组协调员的经纪人掉线,则该组中的每个消费者都将找到剩余的经纪人成为其组的新协调员。 This scenario should not be fatal to your group. 这种情况对您的团队不会致命。

However, monitoring consumer groups is still a very common thing to do in order to track lag, scale in/out if needed or just ensure an important job is actually running! 但是,监视消费者群体仍然是很常见的事情,以跟踪​​滞后,根据需要扩大/缩小规模或仅确保一项重要工作正在运行!

The easiest way is to use the AdminClient APIs, especially: 最简单的方法是使用AdminClient API,尤其是:

Alternatively you can run the kafka-consumer-groups.sh tool to retrieve details about groups. 或者,您可以运行kafka-consumer-groups.sh工具来检索有关组的详细信息。 That displays the current position, lag and client ids or members. 显示当前位置,滞后和客户ID或成员。

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

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