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

bugfix: graceful consumer shutdown #178

Merged
merged 1 commit into from
Jul 23, 2024
Merged
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
20 changes: 10 additions & 10 deletions consume.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,26 @@ func NewConsumer(
// Run starts consuming with automatic reconnection handling. Do not reuse the
// consumer for anything other than to close it.
func (consumer *Consumer) Run(handler Handler) error {
err := consumer.startGoroutines(
handler,
consumer.options,
)
if err != nil {
return err
}

handler = func(d Delivery) (action Action) {
handlerWrapper := func(d Delivery) (action Action) {
if !consumer.handlerMu.TryRLock() {
return NackRequeue
}
defer consumer.handlerMu.RUnlock()
return handler(d)
}

err := consumer.startGoroutines(
handlerWrapper,
consumer.options,
)
if err != nil {
return err
}

for err := range consumer.reconnectErrCh {
consumer.options.Logger.Infof("successful consumer recovery from: %v", err)
err = consumer.startGoroutines(
handler,
handlerWrapper,
consumer.options,
)
if err != nil {
Expand Down
Loading