用Zookeeper保存kafka的偏移量
话不多说,直接上代码
//从ZK获取offset
def getOffsetFromZookeeper(kafkaCluster: KafkaCluster, kafkaGroup: String, kafkaTopicSet: Set[String]): Map[TopicAndPartition, Long] = {
// 创建Map存储Topic和分区对应的offset
val topicPartitionOffsetMap = new mutable.HashMap[TopicAndPartition, Long]()
// 获取传入的Topic的所有分区
// Either[Err, Set[TopicAndPartition]] : Left(Err) Right[Set[TopicAndPartition]]
val topicAndPartitions: Either[Err, Set[TopicAndPartition]]= kafkaCluster.getPartitions(kafkaTopicSet)
// 如果成功获取到Topic所有分区
// topicAndPartitions: Set[TopicAndPartition]
if (topicAndPartitions.isRight) {
// 获取分区数据
// partitions: Set[TopicAndPartition]
val partitions: Set[TopicAndPartition] = topicAndPartitions.right.get
// 获取指定分区的offset
// offsetInfo: Either[Err, Map[TopicAndPartition, Long]]
// Left[Err] Right[Map[TopicAndPartition, Long]]
val offsetInfo: Either[Err, Map[To