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.

相关推荐
wudl55661 小时前
Flink SQL 与 Kafka 整合详细教程
sql·flink·kafka
virtuousOne3 小时前
Kafka基础
分布式·kafka
虫小宝3 小时前
Java分布式架构下的电商返利APP技术选型与架构设计实践
java·分布式·架构
007php0073 小时前
百度面试题解析:Zookeeper、ArrayList、生产者消费者模型及多线程(二)
java·分布式·zookeeper·云原生·职场和发展·eureka·java-zookeeper
waving-black4 小时前
windows系统下安装测试kafka
windows·分布式·kafka
深思慎考4 小时前
RabbitMQ 入门:基于 AMQP-CPP 的 C++ 实践指南与二次封装
开发语言·c++·分布式·rabbitmq·api
Andya_net4 小时前
Java | 基于redis实现分布式批量设置各个数据中心的服务器配置方案设计和代码实践
java·服务器·分布式
沉默终止15 小时前
Kafka Queue: 完成 alterShareGroupOffsets Api
kafka
大数据0017 小时前
CLICKHOUSE分布式表初体验
分布式·clickhouse
失散1317 小时前
分布式专题——43 ElasticSearch概述
java·分布式·elasticsearch·架构