-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti.go
66 lines (53 loc) · 1.25 KB
/
multi.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
63
64
65
66
package kafka
import (
"fmt"
"github.com/babex-group/babex"
"github.com/bsm/sarama-cluster"
)
func multiListen(adapter *Adapter) {
defer close(adapter.multi)
for {
select {
case part, ok := <-adapter.Consumer.Partitions():
if !ok {
return
}
go func(pc cluster.PartitionConsumer) {
ch := make(chan *babex.Message)
defer close(ch)
adapter.logger.Log(fmt.Sprintf("debug: get partition %v for %s", pc.Partition(), pc.Topic()))
babexChannel := babex.NewChannel(ch)
babexChannel.Info = map[string]interface{}{
"topic": pc.Topic(),
"partition": pc.Partition(),
}
adapter.multi <- babexChannel
for msg := range pc.Messages() {
adapter.logger.Log(
fmt.Sprintf(
"debug: get message in %v for %s. offset - %v",
pc.Partition(),
pc.Topic(),
msg.Offset,
),
)
m, err := adapter.options.ConvertMessage(adapter.Consumer, msg)
if err != nil {
adapter.err <- err
adapter.Consumer.MarkOffset(msg, "")
continue
}
ch <- m
adapter.logger.Log(
fmt.Sprintf(
"debug: success publish in %v for %s. offset - %v",
pc.Partition(),
pc.Topic(),
msg.Offset,
),
)
}
}(part)
}
}
}