@@ -2352,8 +2352,42 @@ func (cl *Client) MarkCommitRecords(rs ...*Record) {
23522352// processing records, you can call this function in a goroutine.
23532353func (cl * Client ) CommitUncommittedOffsets (ctx context.Context ) error {
23542354 // This function is just the tail end of CommitRecords just above.
2355+ return cl .commitOffsets (ctx , cl .UncommittedOffsets ())
2356+ }
2357+
2358+ // CommitMarkedOffsets issues a synchronous offset commit for any
2359+ // partition that has been consumed from that has marked offsets.
2360+ // Retriable errors are retried up to the configured retry limit, and any
2361+ // unretriable error is returned.
2362+ //
2363+ // This function is useful as a simple way to commit offsets if you have
2364+ // marked offsets with MarkCommitRecords when using AutoCommitMarks. As an
2365+ // alternative if you want to commit specific records, see CommitRecords.
2366+ //
2367+ // Simple usage of this function may lead to duplicate records if a consumer
2368+ // group rebalance occurs before or while this function is being executed. You
2369+ // can avoid this scenario by calling CommitRecords in a custom
2370+ // OnPartitionsRevoked, but for most workloads, a small bit of potential
2371+ // duplicate processing is fine. See the documentation on DisableAutoCommit
2372+ // for more details. You can also avoid this problem by using
2373+ // BlockRebalanceOnCommit, but that option comes with its own tradeoffs (refer
2374+ // to its documentation).
2375+ //
2376+ // The recommended pattern for using this function is to have a poll / process
2377+ // / commit loop. First PollFetches, then process every record,
2378+ // call MarkCommitRecords for the records you wish the commit and then call
2379+ // CommitMarkedOffsets.
2380+ //
2381+ // If you do not want to wait for this function to complete before continuing
2382+ // processing records, you can call this function in a goroutine.
2383+ func (cl * Client ) CommitMarkedOffsets (ctx context.Context ) error {
2384+ // This function is just the tail end of CommitRecords just above.
2385+ return cl .commitOffsets (ctx , cl .MarkedOffsets ())
2386+ }
2387+
2388+ func (cl * Client ) commitOffsets (ctx context.Context , offsets map [string ]map [int32 ]EpochOffset ) error {
23552389 var rerr error
2356- cl .CommitOffsetsSync (ctx , cl . UncommittedOffsets () , func (_ * Client , _ * kmsg.OffsetCommitRequest , resp * kmsg.OffsetCommitResponse , err error ) {
2390+ cl .CommitOffsetsSync (ctx , offsets , func (_ * Client , _ * kmsg.OffsetCommitRequest , resp * kmsg.OffsetCommitResponse , err error ) {
23572391 if err != nil {
23582392 rerr = err
23592393 return
0 commit comments