mostafa/xk6-kafka

How can one read the last x messages from a topic with a reader?

Bogdan405 opened this issue · 6 comments

How can one read the last x messages from a topic with a reader?

Hey @Bogdan405,

I haven't tested this before, but if you know the offset, you can set it using the ReaderConfig offset and the limit in the consume method to the number of messages you want to read.

Thank you, can I set the offset to the latest message somehow? Or is there a way to get the current offset without consuming all the messages?

@Bogdan405
There is currently no explicit way to do it, unless you read a single message (limit=1).

Ok, I will keep experimenting

I'll close this issue, and feel free to re-open it if the issue is not resolved.

@Bogdan405 , how did you solve your requirement? I am trying to get the last message as well.