[英]Difference between poll and consume in Kafka Confluent library
The github examples page for the Confluent Kafka library lists two methods, namely poll and consume. Confluent Kafka库的github示例页面列出了两种方法,即poll和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. 我确实在Confluent Kafka库中查看了Consumer实现,感觉它们在功能上是相同的,并且仅在它们返回的内容方面有所不同。
Poll() calls consume() to see if there is a message ready to be picked up, and if yes, invokes the OnMessage event. Poll()调用consume()来查看是否有准备好接收的消息,如果是,则调用OnMessage事件。 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
我觉得区别在于实施,功能上它们是相同的https://github.com/confluentinc/confluent-kafka-dotnet/blob/master/src/Confluent.Kafka/Consumer.cs
You are right. 你是对的。 https://github.com/confluentinc/confluent-kafka-dotnet/blob/3f48e8944242abf631ea8d2cd5698f6e149e0731/src/Confluent.Kafka/Consumer.cs#L1147
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. Poll
与Consume
相同,只是暴露具有不同语义的消息。 Consume
will return message in out
parameter whereas Poll
return null and will fire OnMessage
event. Consume
将在out
参数中返回消息,而Poll
返回null并将触发OnMessage
事件。
Edit: in v1 there is only Consume
call left, no more confusion. 编辑:在v1中只剩下
Consume
调用,不再混淆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.