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.

相关推荐
qq_297574679 小时前
第十四篇:RabbitMQ监控与日志分析——快速排查线上问题
分布式·rabbitmq·ruby
小的~~9 小时前
CentOS7安装CDH6.3.2
hive·hdfs·kafka
2401_8401922711 小时前
k8s的crd、operator、cr分别是什么?
运维·分布式·kubernetes·prometheus
covco13 小时前
星链引擎矩阵系统:分布式任务调度与万级账号批量作业自动化技术实践
分布式·矩阵·自动化·批量作业
Little Tomato15 小时前
深入浅出高并发:从 JVM 锁竞争到分布式事务的性能博弈
jvm·分布式
zshs00016 小时前
从 Raft 到 MySQL:我是怎么推导出半同步复制原理的
数据库·分布式·mysql
凯瑟琳.奥古斯特16 小时前
页面置换算法详解与对比
开发语言·分布式·职场和发展
KANGBboy17 小时前
hadoop冷热数据分离
大数据·hadoop·分布式
skilllite作者17 小时前
Evotown——开启本地化、可验证的AI智能体进化新时代
人工智能·分布式·安全·搜索引擎·agentskills
敏君宝爸17 小时前
RabbitMQ多线程消费与死信队列方案
分布式·rabbitmq