I have a .NET Consumer and I want it to read always from the end of the topic. AutoOffsetReset.Latest won’t solve this, since the Consumer could reconnect after a disconnect. In that scenario, I don’t want to read the messages that are posted on the topic when the Consumer was disconnected. I want to get only those messages after the subsequent connect after the disconnect.
Is there a code example of how to always read from the end ?
Would it make sense to use the following code for achieving the above goal?
private void SetOffsetToEnd(IConsumer<Ignore, string> consumer, string topic)
{
List<string> topics = new List<string> { topic };
consumer.Assign(topics.Select(topic => new TopicPartitionOffset(topic, 0, Offset.End)).ToList());
var offsets = consumer.Assignment.Select(partition => new TopicPartitionOffset(partition, Offset.End));
foreach (var offset in offsets)
{
consumer.Seek(offset);
}
}