-
Notifications
You must be signed in to change notification settings - Fork 2
/
kop_fetch.go
48 lines (46 loc) · 1.52 KB
/
kop_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
46
47
48
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) ReactFetch(ctx *NetworkContext, req *codec.FetchReq) (*codec.FetchResp, error) {
if !b.checkSasl(ctx) {
return nil, fmt.Errorf("connection is not authed")
}
logrus.Debugf("fetch req: %+v", req)
for _, topicReq := range req.TopicReqList {
if !b.checkSaslTopic(ctx, topicReq.Topic, constant.ConsumerPermissionType) {
return nil, fmt.Errorf("check topic read permission failed: %s", topicReq.Topic)
}
}
lowTopicRespList, err := b.FetchAction(ctx.Addr, req)
if err != nil {
return nil, fmt.Errorf("fetch failed: %v", err)
}
resp := codec.NewFetchResp(req.CorrelationId)
resp.TopicRespList = lowTopicRespList
for i, lowTopicResp := range lowTopicRespList {
for _, p := range lowTopicResp.PartitionRespList {
if p.RecordBatch != nil {
p.RecordBatch = &codec.RecordBatch{
Offset: p.RecordBatch.Offset,
MessageSize: p.RecordBatch.MessageSize,
LeaderEpoch: p.RecordBatch.LeaderEpoch,
MagicByte: 2,
Flags: 0,
LastOffsetDelta: p.RecordBatch.LastOffsetDelta,
FirstTimestamp: p.RecordBatch.FirstTimestamp,
LastTimestamp: p.RecordBatch.LastTimestamp,
ProducerId: -1,
ProducerEpoch: -1,
BaseSequence: p.RecordBatch.BaseSequence,
Records: p.RecordBatch.Records,
}
}
}
resp.TopicRespList[i] = lowTopicResp
}
return resp, nil
}