Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

.net - what will happen after the Kafka consumer reads the whole partion?

I do have a .Net code that I'm using in a windows service that has the process of initializing a consumer object and consuming the Kafka.

var config = new ProducerConfig
{
    BootstrapServers = "host1:9092,host2:9092,...",
    ClientId = ...,
    ...
};


ConsumerBuilder<byte[], byte[]> c = new ConsumerBuilder<byte[], byte[]>(config ).SetErrorHandler(_Consumer_OnError);

consumer = c.Build();

consumer.Subscribe(topics);

while (!canceled)
{
      var consumeResult = consumer.Consume(cancellationToken);
      //handle consumed message.
      ...
}

I want to know that what will happen after all the messages are consumed from the partition. FYI: There are 3 partitions and 4 nodes for consuming the information.

question from:https://stackoverflow.com/questions/65858970/what-will-happen-after-the-kafka-consumer-reads-the-whole-partion

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From confluent-kafka-dotnet, ConsumeResult<T1, T2> Consume(CancellationToken ct) method will:

Poll for new messages/events. Blocks until a consume result is available or the operation has been cancelled.

This means calling Consume() will never really stop trying to consume messages from the partition (unless something crashes or you cancel the op). So if you have two events in a partition, the third call on Consume() will just block until a new message is written to the partition.

Under the hood during the Consume method, Kafka client keeps making calls to the broker to check whether new events are written to the partition.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...