天天看點

kafka producer.poll producer.flush consumer.poll的差別

參考文獻:https://docs.confluent.io/current/clients/confluent-kafka-python/index.html#consumer

Producer.poll(timeout)

  timeout (float) – Maximum time to block waiting for events. (Seconds)

  Polls the producer for events and calls the corresponding callbacks (if registered).

Producer.flush()

  Wait for all messages in the Producer queue to be delivered. This is a convenience method that calls ​​poll()​​ until ​​len()​​ is zero or the optional timeout elapses.

Producer.poll()和Producer.flush()的差別:

  flush確定所有meg都傳送給broker,對poll的不停調用直到len(Number of messages and Kafka protocol requests waiting to be delivered to broker)為0.

Consumer.poll(timeout): 

  Consume messages, calls callbacks and returns events.

  作用是取資料,傳入的參數:timeout (float) – Maximum time to block waiting for message, event or callback. (Seconds)是等待消息到來的最長時間。