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
| func (k *kafka) Start(checkpoint functionconfig.Checkpoint) error {
var err error
k.consumerGroup, err = k.newConsumerGroup()
if err != nil {
return errors.Wrap(err, "Failed to create consumer")
}
k.shutdownSignal = make(chan struct{}, 1)
// start consumption in the background
go func() {
for {
k.Logger.DebugWith("Starting to consume from broker", "topics", k.configuration.Topics)
// start consuming. this will exit without error if a rebalancing occurs
err = k.consumerGroup.Consume(context.Background(), k.configuration.Topics, k)
if err != nil {
k.Logger.WarnWith("Failed to consume from group, waiting before retrying", "err", errors.GetErrorStackString(err, 10))
time.Sleep(1 * time.Second)
} else {
k.Logger.DebugWith("Consumer session closed (possibly due to a rebalance), re-creating")
}
}
}()
return nil
}
|