Test Result Picture When I use confluent.kafka-net, and I want to ensure the order of kafka message in .netcore, I create a mschannel,
_msChannel = Channel.CreateUnbounded();
when listening, I got a consume result and a received message, and
if (_msChannel.Writer.TryWrite(receivedMessage))
{
_consumer.Pause(new[] { consumeResult.TopicPartition });
// _consumer.StoreOffset(consumeResult);
// Console.WriteLine("Pause:" + sw1.ElapsedTicks + " ,Partition:" + consumeResult.TopicPartition.Partition);
}
And when the message has no error, I use message.Ack()
as follows:
public ValueTask Ack()
{
try
{
_consumer.StoreOffset(_offset);
}
finally
{
var sw = Stopwatch.StartNew();
try
{
_consumer.Resume(new[] { _offset.TopicPartition });
}
catch (Exception e)
{
}
sw.Stop();
Console.WriteLine("Resume:" + sw.ElapsedTicks + " ticks" + " ,Partition:" + _offset.TopicPartition.Partition);
}
return default;
}
The result is that kafka's consumer is very slow, and I found that the reason for that is the partition consume and resume, costs too much time, but I have no better solution to deal with this situation.
in my server test, the consumer consumes ~300 records per minute.