简体   繁体   English

使用 Scala/Spark 编程计算 kafka 主题中的消息数量

[英]Count the number of messages in a kafka topic using Scala/Spark programming

The requirement is to count the number of messages in a Kafka topic using Scala or Spark programming.要求是使用 Scala 或 Spark 编程计算 Kafka 主题中的消息数量。 I am new to both the programming so i am not sure how can it be done.我对这两个编程都很陌生,所以我不确定如何完成。 Can anybody help me with the code or guide me how can it be achieved.任何人都可以帮助我编写代码或指导我如何实现。

The methods for a given org.apache.kafka.clients.consumer.KafkaConsumer are: beginningOffsets(Collection<TopicPartition>) and endOffsets(Collection<TopicPartition>) .给定org.apache.kafka.clients.consumer.KafkaConsumer的方法是: beginningOffsets(Collection<TopicPartition>)endOffsets(Collection<TopicPartition>)

You need to remember that messages can be removed by kafka broker, that's why there is a need for beginning ones.您需要记住,kafka 代理可以删除消息,这就是为什么需要开始的原因。

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

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