Kafka技術知識總結之八——Kafka生產者結構

接上篇《Kafka技術知識總結之七——Kafka磁盤存儲》

八. Kafka 生產者結構

Kafka Producer 主要有三個部分組成:主線程、Sender 線程、RecordAccumulator

  • 主線程:執行序列化、分區、攔截器處理等主要操作,並將消息緩存到 RecordAccumulator 中;
  • Sender 線程:從 RecordAccumulator 中拉數據,發送到 broker;
  • RecordAccumulator:緩存主線程的消息,並提供給 Sender 線程;

生產者執行流程:

  1. 主線程處理數據,包括處理攔截器操作、序列化、分區;
  2. 主線程將數據發送給 RecordAccumulator;
  3. RecordAccumulator 將消息 (ProducerRecord) 壓縮成 (ProducerBatch),並以分區 (TopicPartition) - 消息隊列 (Deque(ProducerBatch)) 的消息存儲主線程發來的消息;
  4. Sender 從 RecordAccumulator 中拉取各分區的消息,並轉換爲 Broker - Deque(ProducerBatch) 的形式(因爲對於 Sender 而言,只關心把消息發送到哪個 Broker 上);
  5. Sender 最後將消息轉換成 Broker - Request 的形式,推送給指定的 Broker;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章