我想知道在Kafka主题中等待消耗的最新消息偏移量,因此我可以与当前消息消耗偏移量进行比较。目标是,一旦我达到最新状态,我将停止消费后来发送的任何消息。
搜索类似的问题,没有人遇到相同的情况 或者如果是这样,它使用的是apache Kafka
答案 0 :(得分:0)
这个怎么样?
DefaultKafkaConsumerFactory<Integer, String> cf = new DefaultKafkaConsumerFactory<>(props);
Consumer<Integer, String> consumer = cf.createConsumer();
consumer.position(new TopicPartition(topic, partition));
您确实创建了原生KafkaConsumer
并使用其position()
:
* Get the offset of the <i>next record</i> that will be fetched (if a record with that offset exists).
* This method may issue a remote call to the server if there is no current position for the given partition.
* <p>
* This call will block until either the position could be determined or an unrecoverable error is
* encountered (in which case it is thrown to the caller).
但是你仍然可以通过Spring为Kafka API重用配置。