@@ -36,6 +36,11 @@ type Consumer interface {
36
36
// CommitMessage commits the offset of a given message.
37
37
CommitMessage (msg * kafkalib.Message ) error
38
38
39
+ // StoreOffset stores the offset of a given message. The offset will be asynchronously flushed to kafka every
40
+ // `auto.commit.interval.ms`. This method is non-blocking and will be faster than `CommitMessage`, however it has
41
+ // weaker delivery guarantees.
42
+ StoreOffset (msg * kafkalib.Message ) error
43
+
39
44
// GetMetadata gets the metadata for a consumer.
40
45
GetMetadata (allTopics bool ) (* kafkalib.Metadata , error )
41
46
@@ -337,6 +342,20 @@ func (cc *ConfluentConsumer) CommitMessage(msg *kafkalib.Message) error {
337
342
return errors .Wrap (err , "failed committing Kafka message" )
338
343
}
339
344
345
+ // StoreOffset stores the offset of a given message. The offset will be asynchronously flushed to kafka every
346
+ // `auto.commit.interval.ms`. This method is non-blocking and will be faster than `CommitMessage`, however it has
347
+ // weaker delivery guarantees.
348
+ func (cc * ConfluentConsumer ) StoreOffset (msg * kafkalib.Message ) error {
349
+ if msg .TopicPartition .Error != nil {
350
+ return errors .New ("can't commit errored message" )
351
+ }
352
+
353
+ offsets := []kafkalib.TopicPartition {msg .TopicPartition }
354
+ offsets [0 ].Offset ++
355
+ _ , err := cc .c .StoreOffsets (offsets )
356
+ return err
357
+ }
358
+
340
359
// Pause pauses consumption of the provided partitions
341
360
func (cc * ConfluentConsumer ) Pause (p []kafkalib.TopicPartition ) error {
342
361
err := cc .c .Pause (p )
0 commit comments