Difference between poll and consume in Kafka Confluent library
Asked Answered
T

1

12

The github examples page for the Confluent Kafka library lists two methods, namely poll and consume. What is the difference between the two.

I did look at the Consumer implementation in the Confluent Kafka library here , and feel they're functionally the same, and differ only in terms of what they return.

Poll() calls consume() to see if there is a message ready to be picked up, and if yes, invokes the OnMessage event. Whereas, consume, saves the message in one of it's parameters, and returns a boolean. I feel difference is in implementation, and functionally they're the same https://github.com/confluentinc/confluent-kafka-dotnet/blob/master/src/Confluent.Kafka/Consumer.cs

Tabb answered 26/4, 2018 at 6:20 Comment(1)
Seems like Consume just fills the output and return true/false if message are returned, and poll does the same but also trigger an event when there are messages...Rosebud
H
5

You are right. https://github.com/confluentinc/confluent-kafka-dotnet/blob/3f48e8944242abf631ea8d2cd5698f6e149e0731/src/Confluent.Kafka/Consumer.cs#L1147

Poll is the same as Consume, just expose message with different semantic. Consume will return message in out parameter whereas Poll return null and will fire OnMessage event.

Edit: in v1 there is only Consume call left, no more confusion.

Handhold answered 13/6, 2018 at 15:16 Comment(1)
Just an FYI: more recent versions (eg 1.0 beta) no longer have the Poll function w/OnMessage event - it's all just through the Consume function.Forte

© 2022 - 2024 — McMap. All rights reserved.