librdkafka contains the function rd_kafka_position which fetches the current offsets for the given topic-partitions. But the comment says:
The \p offset field of each requested partition will be set to the offset of the last consumed message + 1, or RD_KAFKA_OFFSET_INVALID in case there was no previous message.
In other words, it won't give you any useful information if no messages have been consumed yet.
I'm interested in the case where I've just subscribed to a topic, and I've already called rd_kafka_seek to either:
- seek to a known position (in the case of error recovery), or
- seek to the very end of the partition.
What I'd like to know, in this context, is what the offset would be for the next message if one were to be consumed. In other words, in the first case, it should be the same offset that was passed to rd_kafka_seek, and in the second case, it should be 1 plus the offset of the last message that was in the partition when rd_kafka_seek was called.
Unfortunately, just like the comment says, rd_kafka_position doesn't return this information. If no messages have been consumed yet, it gives -1001 (RD_KAFKA_OFFSET_INVALID). If I consume a message and then call rd_kafka_position, it gives the correct offset.
Is there some other function that I can call in order to get the offset before consuming any messages?