kafka要等一段時間才能消費到數據
為什么用python寫的kafka客戶端腳本,程序一運行就能生產數據,而要等一段時間才能消費到數據(topic里面有數據)。(pykafka和confluentKafka都一樣)
只有極少的概率立刻可以消費到數據,大多數都要等個幾分鍾,很影響測試效率。
- 自己封裝的一個給予confluentKafka的consumer對象
- 調用,topic里面是有內容的等一段時間也是可以消費到數據的
閱讀 4.8k
更新於 2018-06-19

https://stackoverflow.com/que... 最下面的回答,注意conf中session.timeout.ms參數的設置。
幾分鍾不應該啊,能把代碼貼下么
ok
session.timeout.ms設置的太大了,導致了這個原因,感謝回答!
你在實例化consumer對象的時候加這樣兩個參數session_timeout_ms=6000,heartbeat_interval_ms=2000
consumer = KafkaConsumer(self.kafkatopic, group_id = self.groupid, bootstrap_servers = '{kafka_host}:{kafka_port}'.format( kafka_host=self.kafkaHost, kafka_port=self.kafkaPort ), session_timeout_ms=6000, heartbeat_interval_ms=2000)
官網里有參數的解釋https://kafka-python.readthed...
主要是這句話:“ If no heartbeats are received by the broker before the expiration of this session timeout, then the broker will remove this consumer from the group and initiate a rebalance.”
另外本機的session_timeout_ms默認值我的是30s,不是官網里說的10s!
更改了參數還是會出現這樣的問題