Apache kafka Spring Kafka-访问偏移量从特定偏移量开始消费的时间
我有一个相当直截了当的卡夫卡消费者:Apache kafka Spring Kafka-访问偏移量从特定偏移量开始消费的时间,apache-kafka,spring-kafka,Apache Kafka,Spring Kafka,我有一个相当直截了当的卡夫卡消费者: MessageListener<String, T> messageListener = record -> { doStuff( record.value())); }; startConsumer(messageListener); protected void startConsumer(MessageListener<String, T> messageListener) { Concurrent
MessageListener<String, T> messageListener = record -> {
doStuff( record.value()));
};
startConsumer(messageListener);
protected void startConsumer(MessageListener<String, T> messageListener) {
ConcurrentMessageListenerContainer<String, T> container = new ConcurrentMessageListenerContainer<>(
consumerFactory(this.brokerAddress, this.groupId),
containerProperties(this.topic, messageListener));
container.start();
}
现在的问题是,我无法访问回调中的卡夫卡消费者,因此我无法调用offsetsForTimes
有没有其他方法可以实现这一点?使用
ConsumerAwareRebalanceListener
进行初始搜索(在2.0中引入)
目前的版本是2.2.0
我添加了另一个答案的链接。嗨,Gary,我使用的是apache Kafka consumer,我的offsetfortimes方法只返回几个分区的偏移位置,尽管所有分区都已分配。。我检查ConsumerBalanceListner.onPartitionsAssigned方法接收所有分区,但当我对onPartitionsAssigned方法内的所有分区执行offsetfortimes时,它只返回1或2个分区的偏移位置。你对pblm有什么想法吗?我也在这上面贴了一个问题。最好不要在评论中问新问题,但我知道。将来如果你对一个旧答案发表评论,请添加一个新问题的链接。谢谢Gary。将来当然可以。
@Override
public void onPartitionsAssigned(Map<TopicPartition, Long> assignments,
ConsumerSeekCallback callback) {
assignments.forEach((t, o) -> callback.seek(t.topic(), t.partition(), ?????));
}