1.概述
转载并且补充:原文地址:https://blog.csdn.net/XU906722/article/details/104420045
本文基于Kafka 0.11 版本
2.整体架构
2.1 线程
整个 Kafka 客户端由两个线程协调运行,即Main线程和Sender线程。
在Main线程中由KafkaProducer创建消息,然后通过Interceptor、Serializer和Partitioner之后缓存到RecordAccumulator(消息累加器)中。
Sender线程 负责从RecordAccumulator中获取消息并发送到Kafka中。
2.2 RecordAccumulator
RecordAccumulator主要用来缓存消息以便Sender线程可以批量发送,进而减少网络传输的资源消耗以提升性能。
RecordAccumulator缓存的大小可以通过生产者客户端参数buffer.memory进行配置,默认值是32MB。如果生产者发