Skip to content

Commit

Permalink
Merge pull request #933 from mfaizanse/backoff_sub_opt
Browse files Browse the repository at this point in the history
Added BackOff helper method to set backoff through subOpts
  • Loading branch information
kozlovic committed Apr 4, 2022
2 parents 7623eaa + c47689c commit 8af932f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions example_test.go
Expand Up @@ -620,6 +620,11 @@ func ExampleSubOpt() {
js.Subscribe("foo", func(msg *nats.Msg) {
fmt.Printf("Received a message: %s\n", string(msg.Data))
}, nats.StartTime(time.Now().Add(-2*time.Hour)))

// Start delivering messages with delay based on BackOff array of time durations.
js.Subscribe("foo", func(msg *nats.Msg) {
fmt.Printf("Received a message: %s\n", string(msg.Data))
}, nats.ManualAck(), nats.MaxDeliver(2), nats.BackOff([]time.Duration{50 * time.Millisecond, 250 * time.Millisecond}))
}

func ExampleMaxWait() {
Expand Down
8 changes: 8 additions & 0 deletions js.go
Expand Up @@ -2259,6 +2259,14 @@ func RateLimit(n uint64) SubOpt {
})
}

// BackOff is an array of time durations that represent the time to delay based on delivery count.
func BackOff(backOff []time.Duration) SubOpt {
return subOptFn(func(opts *subOpts) error {
opts.cfg.BackOff = backOff
return nil
})
}

// BindStream binds a consumer to a stream explicitly based on a name.
// When a stream name is not specified, the library uses the subscribe
// subject as a way to find the stream name. It is done by making a request
Expand Down

0 comments on commit 8af932f

Please sign in to comment.