Java,如何在apache kafka中获取主题中的消息数量 [英] Java, How to get number of messages in a topic in apache kafka

查看:553
本文介绍了Java,如何在apache kafka中获取主题中的消息数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用apache kafka进行消息传递。我用Java实现了生产者和使用者。我们如何获得主题中的消息数量?

I am using apache kafka for messaging. I have implemented the producer and consumer in Java. How can we get the number of messages in a topic?

推荐答案

从消费者角度想到这一点的唯一方法视图是实际使用消息并计算它们。

The only way that comes to mind for this from a consumer point of view is to actually consume the messages and count them then.

Kafka经纪人公开了自启动以来收到的消息数量的JMX计数器,但你不知道已经清除了多少消息。

The Kafka broker exposes JMX counters for number of messages received since start-up but you cannot know how many of them have been purged already.

在大多数常见情况下,Kafka中的消息最好被视为无限流,并且获得当前保留在磁盘上的数量的离散值是不相关的。此外,在处理一个经纪人群集时,事情变得更加复杂,这些经纪人都有一个主题中的消息子集。

In most common scenarios, messages in Kafka is best seen as an infinite stream and getting a discrete value of how many that is currently being kept on disk is not relevant. Furthermore things get more complicated when dealing with a cluster of brokers which all have a subset of the messages in a topic.

这篇关于Java,如何在apache kafka中获取主题中的消息数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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