Reputation: 1326
im new to Kafka and KafkaJS.
Im trying to find a way to get the last n messages sent to a topic, instead of getting all non-consumed messages of that topic.
For example, I have a producer that produces 1 message per second and let it wait for 5 seconds.
Then, when I start the consumer, the consumer gets all 5 messages. ( Only 1 consumer running, 1 group, 1 partition, same topic as producer ).
Is there a configuration on KafkaJS to get only the last n produced messages?
Upvotes: 3
Views: 4759
Reputation: 191864
You could poll a single record, or otherwise list the offsets of the topic beforehand.
Then you can seek
a consumer to high_offset - N
and start polling from there
Upvotes: 4