-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
62 lines (52 loc) · 1.21 KB
/
metadata.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package kafkamock
import (
"bufio"
)
type (
metadataRequestV1 struct {
Topics []string
}
metadataResponseV1 struct {
Brokers []brokersV1
ControllerId int32
Topics []topicsV1
}
brokersV1 struct {
NodeId int32
Host string
Port int32
Rack NullableString
}
topicsV1 struct {
ErrorCode int16
Name string
IsInternal bool
Partitions []partitionV1
}
partitionV1 struct {
ErrorCode int16
PartitionIndex int32
LeaderId int32
ReplicaNodes []int32
IsrNodes []int32
}
)
const kLeaderNode = 100
func metadataV1(reader *bufio.Reader, kc *kafkaClient, kmh *kafkaMessageHeader) (response any, rtags map[int]any, err error) {
request, err := readRequest[metadataRequestV1](reader)
if err != nil {
return
}
topics := make([]topicsV1, 0, len(request.Topics))
for _, t := range request.Topics {
topics = append(topics, topicsV1{Name: t, Partitions: []partitionV1{{PartitionIndex: 2, LeaderId: kLeaderNode, ReplicaNodes: []int32{1}, IsrNodes: []int32{1}}}})
}
response = &metadataResponseV1{
Brokers: []brokersV1{
{NodeId: kLeaderNode, Host: "localhost", Port: int32(kc.serverPort)},
},
ControllerId: 500,
Topics: topics,
}
return
}