请教大神,kafka使用时间戳获取offsets中,当时间戳是当前时间时,为什么获取到的offset是null?

请教大神,kafka使用时间戳获取offsets中,当时间戳是当前时间时,为什么获取到的offset是null?

使用的java api是:

Map<TopicPartition, Long> topicPartitionLongMap = new HashMap<>(); TopicPartition topicPartition = new TopicPartition(topic, partition); topicPartitionLongMap.put(topicPartition, timestamp); Map<TopicPartition, OffsetAndTimestamp> offsetMap = consumer.offsetsForTimes(topicPartitionLongMap); 
return offsetMap.get(topicPartition).offset();

获取到的offsets是null

已邀请:

空心菜 - 心向阳光,茁壮成长

offsets 你通过其他工具看是null吗?,比如你通过kafkamanager工具。 我不懂Java哦,不知道是不是默认如果没有数据,就是返回字符串null.  如果不是 ,我还以是你集群搭建可能有问题,在topic创建上。

要回复问题请先登录注册