- 0
- 0
- 约6.01千字
- 约 30页
- 2026-01-22 发布于北京
- 举报
—课程概要
a消费者编程模型
a消费者的Python和Java客户端实现
a生产者编程模型
a生产者的Python和Java客户端实现
Kafka消费者编程模型
程模型—知识点
消费模型
roup)消费模型
消费模型对比
程模型—分区消费模型
分区消费架构图
程模型—分区消费模型
分区消费伪代码描述
ain()
获取分区的size
forindex=0tosize
createthread(orprocess)consumer(Index)
index个线程(进程)
nsumer(index)
创建到kafkabroker的连接:KafkaClient(host,port)
指定消费参数构建consumer:SimpleConsumer(topic,partitions)
设置消费offset:consumer.seek(offset,0)
whileTrue
消费指定topic第index个分区的数据
处理
记录当前消息offset
提交当前offset(可选)
程模型—组(Group)消费模型
组消费架构图
程模型—组(Group)消费模型
按组(Group)消费伪代码描述
main()
设置需要创建的流数N
forindex=0toN
createthreadconsumer(Index)
第index个线程
onsumer(index)
创建到kafkabroker的连接:KafkaClient(host,port)
指定消费参数构建consumer:SimpleConsumer(topic,partitions)
设置从头消费还是从的消费(smalt或largest)
whileTrue
从指定topic的第index个流取数据
处理
(offset会自动提交到zookeeper,无需我们操作)
程模型—组(Group)消费模型
Consumer分配算法
topicTthatCisubscribesto
eallpartitionsproducingtopicT
eallconsumersinthesamegroupasCithatconsumetopicT
sopartitionsonthesamebrokerareclusteredtogether)
heindexpositionofCiinCGandletN=size(PT)/size(CG)
artitionsfromi*Nto(i+1)*N-1toconsumerCi
currententriesownedbyCifrom
原创力文档

文档评论(0)