3

I'm trying to get the Kafka offset using Confluent Kafka.

This is the code I'm using to obtain it:

var offsetPosition = consumer.Position(new TopicPartition(topicConfiguration.Topic, topicConfiguration.Partition));

It always gives me a value of -1001 though. What am I doing wrong?

Additional Info

I think this is may because it is Unset. This is what the doc says:

Unset in case there was no previous message consumed by this consumer.

I'm not sure what I should do with this though.

runnerpaul
  • 5,942
  • 8
  • 49
  • 118
  • 2
    Well, like the message says, it means that no one has consumed that topic partition and committed the offset. So by default it returns `Unset (-1001)`. What output are you expecting? – rytisk Mar 01 '21 at 10:52

1 Answers1

2

You aren't doing anything wrong, that is the default value. From the docs:

If an offset value of Offset.Invalid (-1001) is specified, consumption will resume from the last committed offset, or according to the 'auto.offset.reset' configuration parameter if no offsets have been committed yet.

If you want to specify where to start from, you can use the consumer.Assign method.

Pickled
  • 465
  • 1
  • 4
  • 10
  • This should be the same for other languages btw, I found this while using the Python confluent_kafka client – Pickled Jun 29 '21 at 13:25