Skip to content

Reader without consumer group read at last offset #1368

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

Open
zekth opened this issue Feb 14, 2025 · 3 comments · May be fixed by #1386
Open

Reader without consumer group read at last offset #1368

zekth opened this issue Feb 14, 2025 · 3 comments · May be fixed by #1386

Comments

@zekth
Copy link

zekth commented Feb 14, 2025

Describe the solution you would like

Currently the implementation when spinning a consumer without consumer group will always start at the first offset:

offset: FirstOffset,

Would it be possible to support the StartOffset parameter instead?

The goal in here is to spin a consumer without a consumer group idea to get only the latest offsets

@ns-gzhang
Copy link

There is a way to work around to see if it fits your need. Here is how we did it to read from any offset:

  1. Get the first and last offsets on a topic/partition:
    ...
    conn, err = dialer.DialLeader(ctx, "tcp", broker, k.Topic, k.Partition) // we use kafka.DefaultDialer
    if err != nil {
         // should retry, or another broker
    }
    first, last, err = conn.ReadOffsets()
   ...
  1. use the above offsets to set your desired starting offset k.Offset between first and last (inclusive):
        k.client = kafka.NewReader(config)
	_ = k.client.SetOffset(k.Offset)
        ...
        m, err := k.client.ReadMessage(k.context)

@petedannemann
Copy link
Contributor

Yeah this seems reasonable and was probably a mistake in the initial implementation, can you submit a PR with the change?

@zekth
Copy link
Author

zekth commented Mar 21, 2025

I'll try to find an implementation to avoid breaking changes in the initial behavior.

@zekth zekth linked a pull request May 14, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants