Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Expose MarkOffset on PartitionConsumer #203

Closed
gaffneyc opened this issue Dec 26, 2017 · 3 comments
Closed

Expose MarkOffset on PartitionConsumer #203

gaffneyc opened this issue Dec 26, 2017 · 3 comments

Comments

@gaffneyc
Copy link

gaffneyc commented Dec 26, 2017

I'm prototyping a worker that uses PartitionConsumers to ensure there is a Go routine running for each subscribed partition. Minor annoyance is that I need to pass a reference to the top level Consumer to the workers in order to mark offsets. If a version of MarkOffset was exposed on PartitionConsumer it would alleviate the need.

It looks like there is already MarkOffset(int64, string) on PartitionConsumer but it's not exposed as part of the interface and seems to expect msg.Offset + 1 which could cause confusion if exposed as is.

Rough sketch of what I'm doing

func main() {
  consumer, _ := cluster.NewConsumer(...)

  go func() {
    for part := range consumer.Partitions() {
      go worker(consumer, part)
    }
  }
}

func worker(consumer *cluster.Consumer, part cluster.PartitionConsumer) {
  for msg := part.Messages() {
    // process

    // If only this could be part.MarkOffset(msg, "")
    consumer.MarkOffset(msg, "")
  }
}

I'm also not sure if this approach is strictly necessary. So if I'm overthinking it I would appreciate some course correction.

@dim
Copy link
Member

dim commented Jan 2, 2018

I looked at the code and I don't see an immediate problem with exposing it, but do you mind calling part.MarkOffset(msg.Offset, "") instead?

@gaffneyc
Copy link
Author

gaffneyc commented Jan 2, 2018

I'm fine with calling part.MarkOffset(msg.Offset, "") the only concern on my end is that consumer.MarkOffset(msg, "") calls part.MarkOffset(msg.Offset + 1, "") see here.

Is msg.Offset + 1 correct in this case? Is MarkOffset marking the specified offset as completed or is it marking the next offset as where to resume from?

@dim
Copy link
Member

dim commented Jan 16, 2018

Continuing in #209

@dim dim closed this as completed Jan 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants