Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop at end of topic/partition #848

Closed
arnaud-lb opened this issue Mar 15, 2017 · 5 comments
Closed

Stop at end of topic/partition #848

arnaud-lb opened this issue Mar 15, 2017 · 5 comments

Comments

@arnaud-lb
Copy link

It doesn't seem to be possible to stop consuming when the end of a partition is reached.

I'm using compacted topics, and one common use-case I have is to start by reading them entirely from the beginning to the end. However, there is no easy way to stop consuming when the end is reached.

I tried a few things, but the library is not making that easy.

Basically, here is what I have to do currently:

  1. Read the newest offset: client.GetOffset(topic, partition, sarama.OffsetNewest)
  2. Consume every message
  3. If a message with offset >= newest offset is seen, stop consuming
  4. If topic is empty, 3 may never happen, so I have to also produce a dummy message before step 1, for instance

It would be awesome if Sarama provided a way to stop consuming when the end of a partition is reached and/or to be notified about it.

@arnaud-lb arnaud-lb changed the title Stop at end of topic Stop at end of topic/partition Mar 15, 2017
@eapache
Copy link
Contributor

eapache commented Mar 15, 2017

Similar to #666 and #628, this is not something we provide because kafka does not really have the concept; the entire design is based on the fact that streams are never-ending.

@eapache eapache closed this as completed Mar 15, 2017
@arnaud-lb
Copy link
Author

I believe that the Kafka protocol notifies the client when the end of the partition is reached ?

librdkafka and librdkafka-based clients also notify the user when the end of the partition is reached.

@eapache
Copy link
Contributor

eapache commented Mar 15, 2017

I believe that the Kafka protocol notifies the client when the end of the partition is reached ?

Not to my knowledge.

@wvanbergen
Copy link
Contributor

wvanbergen commented Mar 15, 2017

It tells you the latest available offset while consuming (HighWaterMark): #339, which you could use for this purpose.

@TheRoSS
Copy link

TheRoSS commented Oct 13, 2022

Here is an answer #2116

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants