Consumer.Committed 返回 null OffsetMetaData
Consumer.Committed returning null OffsetMetaData
Kafka 消费者API 提交returns 空偏移量。不知道哪里出了问题。
val partitions = new util.HashSet[TopicPartition]
for (partitionInfo <- consumer.partitionsFor(topic)) {
partitions.add(new TopicPartition(partitionInfo.topic, partitionInfo.partition))
}
consumer.assign(partitions)
val latestOffset= consumer.committed(partitions)
println ("LatestOffset Object "+ latestOffset)
val map = latestOffset.map{ case(t, o) => t.partition() -> o.offset()}
打印输出:
{partition-1=null, partition-0=null}
最终结果我想得到一个分区映射->偏移像{"0"->200,"1"->100}
为什么 LatestOffset 对象偏移量元数据显示为空?如果我使用 consumer.position 它会起作用。
使用kafka客户端:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.4.1</version>
</dependency>
它显示 null
因为您的消费者从未消费,因此从未提交任何补偿。
让您的消费者使用来自指定主题的消息,提交它们,然后一些值将从 committed
方法中显示出来。
Kafka 消费者API 提交returns 空偏移量。不知道哪里出了问题。
val partitions = new util.HashSet[TopicPartition]
for (partitionInfo <- consumer.partitionsFor(topic)) {
partitions.add(new TopicPartition(partitionInfo.topic, partitionInfo.partition))
}
consumer.assign(partitions)
val latestOffset= consumer.committed(partitions)
println ("LatestOffset Object "+ latestOffset)
val map = latestOffset.map{ case(t, o) => t.partition() -> o.offset()}
打印输出:
{partition-1=null, partition-0=null}
最终结果我想得到一个分区映射->偏移像{"0"->200,"1"->100}
为什么 LatestOffset 对象偏移量元数据显示为空?如果我使用 consumer.position 它会起作用。
使用kafka客户端:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.4.1</version>
</dependency>
它显示 null
因为您的消费者从未消费,因此从未提交任何补偿。
让您的消费者使用来自指定主题的消息,提交它们,然后一些值将从 committed
方法中显示出来。