-
Notifications
You must be signed in to change notification settings - Fork 2
/
kop_offset_fetch.go
45 lines (42 loc) · 1.49 KB
/
kop_offset_fetch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package kop
import (
"fmt"
"github.com/protocol-laboratory/kafka-codec-go/codec"
"github.com/protocol-laboratory/kop-proxy-go/constant"
"github.com/sirupsen/logrus"
)
func (b *Broker) OffsetFetchVersion(ctx *NetworkContext, req *codec.OffsetFetchReq) (*codec.OffsetFetchResp, error) {
if !b.checkSasl(ctx) {
return nil, fmt.Errorf("connection is not authed")
}
logrus.Debugf("offset fetch req: %+v", req)
resp := &codec.OffsetFetchResp{
BaseResp: codec.BaseResp{
CorrelationId: req.CorrelationId,
},
TopicRespList: make([]*codec.OffsetFetchTopicResp, len(req.TopicReqList)),
}
for i, topicReq := range req.TopicReqList {
if !b.server.AuthGroupTopic(topicReq.Topic, req.GroupId) {
return nil, fmt.Errorf("auth group topic failed, topic: %s, group: %s", topicReq.Topic, req.GroupId)
}
if !b.checkSaslTopic(ctx, topicReq.Topic, constant.ConsumerPermissionType) {
return nil, fmt.Errorf("check topic read permission failed: %s", topicReq.Topic)
}
f := &codec.OffsetFetchTopicResp{
Topic: topicReq.Topic,
PartitionRespList: make([]*codec.OffsetFetchPartitionResp, 0),
}
for _, partitionReq := range topicReq.PartitionReqList {
partition, err := b.OffsetFetchAction(ctx.Addr, topicReq.Topic, req.ClientId, req.GroupId, partitionReq)
if err != nil {
return nil, fmt.Errorf("offset fetch failed: %v", err)
}
if partition != nil {
f.PartitionRespList = append(f.PartitionRespList, partition)
}
}
resp.TopicRespList[i] = f
}
return resp, nil
}