-
Notifications
You must be signed in to change notification settings - Fork 0
/
kafka_meta.go
36 lines (33 loc) · 997 Bytes
/
kafka_meta.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
package main
import (
"github.com/Shopify/sarama"
log "github.com/Sirupsen/logrus"
"github.com/golang/protobuf/proto"
"github.com/larskluge/babl-server/kafka"
bn "github.com/larskluge/babl/bablnaming"
pb "github.com/larskluge/babl/protobuf/messages"
)
const ReadLastNMetadataEntries = 1000
func listenToMetadata(client *sarama.Client) {
topic := bn.ModuleToTopic(ModuleName, true)
ch := make(chan *kafka.ConsumerData)
go kafka.ConsumeIncludingLastN(client, topic, 0, ReadLastNMetadataEntries, ch)
for msg := range ch {
var meta pb.Meta
if err := proto.Unmarshal(msg.Value, &meta); err != nil {
log.WithError(err).Warn("Unknown meta data received")
} else {
if meta.Ping != nil {
handlePingRequest(meta.Ping)
}
if meta.Cancel != nil {
handleCancelRequest(meta.Cancel)
}
if meta.Restart != nil && !msg.Historical {
handleRestartRequest(meta.Restart)
}
}
msg.Processed <- "success"
}
log.Panic("listenToMetadada: Lost connection to Kafka")
}