Kafka broker 写消息的过程

text 复制代码
Producer → Kafka Broker → Replication → Consumer
               |
          Partition chosen (by key or round-robin)
               |
          Message appended to end of log (commit log)

上面的流程是kafka 写操作的大体流程。

kafka 不会特意保留message 在内存中,而是直接写入了disk。

那么消费的时候,如果是最近 produced 的message,即使写入了disk,还是会保留在OS的page cache中。 OS page cache 即使是flush 到了disk,也不会被立刻清除,这个是OS 自己的机制。 所以consumer 读最近生产的消息的时候,还是可以从page cache中读取出来的,而不用从disk 中读取。

  1. Kafka Broker Receives the Message

    决定partition

  2. Message is Appended to a Partition Log

    The selected broker appends the message to the end of the partition log (a sequential write).

    Kafka writes messages to disk efficiently using write-ahead logs (WAL).

  3. Replication (for Fault Tolerance)

    Kafka waits for acknowledgments based on the producer's acks setting:

    acks=0: Producer doesn't wait.

    acks=1: Wait for leader only.

    acks=all: Wait for all replicas to acknowledge.

  4. Message is Made Available to Consumers

    Once the acks is fulfilled, it becomes available for consumers.

    Consumers read sequentially using offsets.

    Kafka keeps messages for a retention period (e.g., 7 days), regardless of whether they've been consumed.

相关推荐
计算机毕设定制辅导-无忧学长6 小时前
Kafka 核心架构与消息模型深度解析(二)
架构·kafka·linq
计算机毕设定制辅导-无忧学长6 小时前
Kafka 核心架构与消息模型深度解析(一)
分布式·架构·kafka
Hoking6 小时前
Kafka集群部署(docker容器方式)SASL认证(zookeeper)
docker·zookeeper·kafka
一弓虽6 小时前
zookeeper 学习
分布式·学习·zookeeper
14L7 小时前
互联网大厂Java面试:从Spring Cloud到Kafka的技术考察
spring boot·redis·spring cloud·kafka·jwt·oauth2·java面试
predisw7 小时前
kafka consumer group rebalance
分布式·kafka
明达技术8 小时前
ProfiNet 分布式 IO 在某污水处理厂的应用
分布式
云道轩8 小时前
llm-d:面向Kubernetes的高性能分布式LLM推理框架
分布式·容器·kubernetes
FakeOccupational9 小时前
【p2p、分布式,区块链笔记 MESH】Bluetooth蓝牙通信拓扑与操作 BR/EDR(经典蓝牙)和 BLE
笔记·分布式·p2p
伤不起bb10 小时前
Kafka 消息队列
linux·运维·分布式·kafka