Skip to content

Commit

Permalink
Producer.Retry.BackoffFunc proof of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Lee committed Aug 29, 2018
1 parent 647feef commit 15f1568
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion async_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,14 @@ func (pp *partitionProducer) dispatch() {
if msg.retries > pp.highWatermark {
// a new, higher, retry level; handle it and then back off
pp.newHighWatermark(msg.retries)
time.Sleep(pp.parent.conf.Producer.Retry.Backoff)
var backoff time.Duration
if pp.parent.conf.Producer.Retry.BackoffFunc != nil {
maxRetries := pp.parent.conf.Producer.Retry.Max
backoff = pp.parent.conf.Producer.Retry.BackoffFunc(msg.retries, maxRetries)
} else {
backoff = pp.parent.conf.Producer.Retry.Backoff
}
time.Sleep(backoff)
} else if pp.highWatermark > 0 {
// we are retrying something (else highWatermark would be 0) but this message is not a *new* retry level
if msg.retries < pp.highWatermark {
Expand Down
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ type Config struct {
// (default 100ms). Similar to the `retry.backoff.ms` setting of the
// JVM producer.
Backoff time.Duration
// Called to compute backoff time dynamically. Useful for implementing
// more sophisticated backoff strategies. This takes precedence over
// `Backoff` if set.
BackoffFunc func(retries, maxRetries int) time.Duration
}
}

Expand Down

0 comments on commit 15f1568

Please sign in to comment.