架构
- broker
- topic:按照topic来分类消息。
- partition:一个topic包含多个partttion,parttion里面包含多条消息。
- offset:消息的唯一序号。
- Producer
- Consumer
- Consumer Group
- Zookeeper:保存集群broker,topic,partition等meta数据,还负责broker故障发现,partition leader选举,负载均衡等功能。
消息存储架构
- 每条消息包含了3部分:offset,MessageSize,data。(offset是一个逻辑地址,代表某条消息在partition中的偏移量,可以唯一的确定一条消息的位置)。
- partition由多个segment文件(后缀名.log)组成,每个segment大小相等,顺序读写。可以使用二分查找定位消息在哪个segment文件中。
- 为每一个segment建立了索引(后缀名.index),(message是每隔一定字节的数据建立一个索引,这样做的目的是,可以将索引文件保存到内存中)。