[英]how to consume a kafka topic from a specific offset?
recently I am using kafka, I have a topic and I am using the following code to consume最近我在使用kafka,我有一个主题,我正在使用以下代码来消费
@KafkaListener(topics = "topic_name", groupId = "_id" , id = "pro", containerFactory = "kafkaListenerContainerFactory")
public void consume(ConsumerRecord<String, String> record, Acknowledgment ack) {
kafkaService.proccessorConsumer(record);
ack.acknowledge();
}
every thing works fine, but I need to handle a situation where if the service stopped for any reason, then started I want to continue consuming from the last message that has processed, I do understand that the acknowledgment help with this, but for the sake of certainty I saved the last consumed offset somewhere.一切正常,但我需要处理这样一种情况,如果服务因任何原因停止,然后开始我想继续使用已处理的最后一条消息,我明白确认对此有帮助,但为了方便可以肯定的是,我在某处保存了最后消耗的偏移量。 my question is how I could use that offset to start consuming the topic from it.
我的问题是如何使用该偏移量开始使用它的主题。
As @OneCricketeer indicates, what you are trying to achieve is the default behaviour of the Kafka consumer, if you haven't disabled automatic commit.正如@OneCricketeer 所指出的,如果您没有禁用自动提交,您想要实现的是 Kafka 消费者的默认行为。
You can check this by describing your consumer group using the consumer id as follows, just check that the offset of your consumer is the same as the one you have stored elsewhere.您可以通过如下使用消费者 ID 描述您的消费者组来检查这一点,只需检查您的消费者的偏移量是否与您在其他地方存储的偏移量相同。
> bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group-id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.