@@ -14,6 +14,11 @@ import (
14
14
// ErrSeekTimedOut is the error returned when a consumer timed out during Seek.
15
15
var ErrSeekTimedOut = errors .New ("Kafka Seek timed out. Please try again." )
16
16
17
+ // ConsumerFactory creates a Consumer.
18
+ // You can use it for postponing the creation of a consumer on runtime. E.g. setting an initial offset that you don't know on boot time.
19
+ // NewConsumer and NewDetachedConsumer implements this.
20
+ type ConsumerFactory func (logrus.FieldLogger , Config , ... ConfigOpt ) (Consumer , error )
21
+
17
22
// Consumer reads messages from Kafka.
18
23
type Consumer interface {
19
24
// AssignPartittionByKey sets the current consumer to read from a partion by a hashed key.
@@ -62,7 +67,7 @@ type ConfluentConsumer struct {
62
67
// permission on the group coordinator for managing commits, so it needs a consumer group in the broker.
63
68
// In order to simplify, the default consumer group id is copied from the configured topic name, so make sure you have a
64
69
// policy that gives permission to such consumer group.
65
- func NewDetachedConsumer (log logrus.FieldLogger , conf Config , opts ... ConfigOpt ) (* ConfluentConsumer , error ) {
70
+ func NewDetachedConsumer (log logrus.FieldLogger , conf Config , opts ... ConfigOpt ) (Consumer , error ) {
66
71
// See Reference at https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
67
72
kafkaConf := conf .baseKafkaConfig ()
68
73
_ = kafkaConf .SetKey ("enable.auto.offset.store" , false ) // manually StoreOffset after processing a message. It is mandatory for detached consumers.
@@ -128,7 +133,7 @@ func NewDetachedConsumer(log logrus.FieldLogger, conf Config, opts ...ConfigOpt)
128
133
// NewConsumer creates a ConfluentConsumer based on config.
129
134
// - NOTE if the partition is set and the partition key is not set in config we have no way
130
135
// of knowing where to assign the consumer to in the case of a rebalance
131
- func NewConsumer (log logrus.FieldLogger , conf Config , opts ... ConfigOpt ) (* ConfluentConsumer , error ) {
136
+ func NewConsumer (log logrus.FieldLogger , conf Config , opts ... ConfigOpt ) (Consumer , error ) {
132
137
// See Reference at https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
133
138
kafkaConf := conf .baseKafkaConfig ()
134
139
_ = kafkaConf .SetKey ("enable.auto.offset.store" , false ) // manually StoreOffset after processing a message. Otherwise races may happen.)
0 commit comments