问题描述
我是kafka的新手,试图了解是否有一种方法可以从上一次消耗的偏移量中读取消息,而不是从头开始读取消息.
I am new to kafka and trying to understand if there is a way to read messages from last consumed offset, but not from beginning.
我正在写一个示例案例,以使我的意图不会偏离.
I am writing an example case, so that my intention will not get deviate.
Eg:
1) I produced 5 messages at 7:00 PM and console consumer consumed those.
2) I stopped consumer at 7:10 PM
3) I produced 10 message at 7:20 PM. No consumer had read those messages.
4) Now, i have started console consumer at 7:30 PM, without from-beginning.
5) Now, it Will read the messages produced after it has started. Not the earlier ones, which were produced at 7.20 PM
是否有一种方法可以从上次消耗的偏移量中获取消息?
Is there a way to get the messages produced from last consumed offset.?
推荐答案
是的,可以使用控制台使用者从上一个消耗的偏移量中读取数据.调用kafka-console-consumer时必须添加 consumer.config 标志.
Yes, it is possible to use console consumer to read from the last consumed offset. You have to add consumer.config flag while invoking kafka-console-consumer.
示例:-
[root@sandbox bin]# ./kafka-console-consumer.sh --topic test1 --zookeeper localhost:2181 --consumer.config /home/mrnakumar/consumer.properties
此处/home/mrnakumar/consumer.properties 是一个包含 group.id 的文件./home/mrnakumar/consumer.properties的外观如下:-
Here /home/mrnakumar/consumer.properties is a file containing group.id.Here is how the /home/mrnakumar/consumer.properties looks:-
如果使用consumer.config,则可以从 [开始使用--from-beginning] 读取,也可以仅从日志末尾读取.日志结尾表示使用者启动后发布的所有消息.
Withoug using consumer.config, it is possible to read either from beginning [ by using --from-beginning] or end of the Log only. End of the Log means all the messages published after consumer start.
这篇关于如何使kafka使用者从最后消耗的偏移量读取而不是从开头读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!