go saram 消费者调用逻辑

业务层:

NewConsumer(client.mBrokers, group, topic, config)

cluster-comsuer.go

构造Consumer:
consumer, err := sarama.NewConsumerFromClient(client.Client)
c.client.RefreshCoordinator(groupID)//获取组协调者

起循环

for {

c.nextTick

}

nextTick:

重平衡->订阅主题->fetchOffsets->针对该主题分区下的offset起一个分区消费者->然后调用分区消费者的ConsumePartition

comsumer.go

ConsumePartition(topic string, partition int32, offset int64)->
c.refBrokerConsumer(leader)->
c.newBrokerConsumer(broker)->
go withRecover(bc.subscriptionConsumer)->
bc.fetchNewMessages()->
bc.broker.Fetch(request)

broker.go

 b.sendAndReceive(request, response)->
versionedDecode(buf, res, req.version())  and res is 
respons, response is FetchResponse type

encode_decoder.go

in.decode(&helper, version)  FetchResponse type decode is:

fetch_repsonse.go

decode(pd packetDecoder, version int16)->
records.decode(recordsDecoder);

records.go

decode(pd packetDecoder)->

record_batch.go

decode(pd packetDecoder) include 解压缩

 

 

你可能感兴趣的:(KAFKA)