Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BatchNoWait parameter #1167

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ type Writer struct {
// The default is to use a kafka default value of 1048576.
BatchBytes int64

// Setting this flag to true causes the writer to flush batches of messages
// either when the number of messages reaches BatchSize or when the number of
// unprocessed messages less than BatchSize.
BatchNoWait bool

// Time limit on how often incomplete message batches will be flushed to
// kafka.
//
Expand Down Expand Up @@ -1059,6 +1064,15 @@ func (ptw *partitionWriter) writeMessages(msgs []Message, indexes []int32) map[*
batches[batch] = append(batches[batch], i)
}
}

// Useful for sync writers, where we want to flush the batch immediately
// if there are no more messages to write.
if ptw.w.BatchNoWait && ptw.currBatch != nil {
ptw.currBatch.trigger()
ptw.queue.Put(ptw.currBatch)
ptw.currBatch = nil
}

return batches
}

Expand Down