How to make kafka consumer to read from last consumed offset but not from beginning

后端 未结 3 1750
刺人心
刺人心 2021-01-04 10:24

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 tha

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-04 10:52

    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.

    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.

    Example:-

    [root@sandbox bin]# ./kafka-console-consumer.sh --topic test1 --zookeeper localhost:2181 --consumer.config /home/mrnakumar/consumer.properties
    

    Here /home/mrnakumar/consumer.properties is a file containing group.id. Here is how the /home/mrnakumar/consumer.properties looks:-

    group.id=consoleGroup

    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.

提交回复
热议问题