Skip to content

Commit

Permalink
improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
wagslane committed Mar 20, 2023
1 parent b36df88 commit 05646d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
4 changes: 3 additions & 1 deletion consume.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ func NewConsumer(
*options,
)
if err != nil {
consumer.options.Logger.Errorf("error restarting consumer goroutines after cancel or close: %v", err)
consumer.options.Logger.Fatalf("error restarting consumer goroutines after cancel or close: %v", err)
consumer.options.Logger.Fatalf("consumer closing, unable to recover")
return
}
}
}()
Expand Down
27 changes: 13 additions & 14 deletions publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,19 @@ func NewPublisher(conn *Conn, optionFuncs ...func(*PublisherOptions)) (*Publishe
return nil, err
}

go publisher.handleRestarts()
go func() {
for err := range publisher.reconnectErrCh {
publisher.options.Logger.Infof("successful publisher recovery from: %v", err)
err := publisher.startup()
if err != nil {
publisher.options.Logger.Fatalf("error on startup for publisher after cancel or close: %v", err)
publisher.options.Logger.Fatalf("publisher closing, unable to recover")
return
}
go publisher.startReturnHandler()
go publisher.startPublishHandler()
}
}()

return publisher, nil
}
Expand All @@ -119,19 +131,6 @@ func (publisher *Publisher) startup() error {
return nil
}

func (publisher *Publisher) handleRestarts() {
for err := range publisher.reconnectErrCh {
publisher.options.Logger.Infof("successful publisher recovery from: %v", err)
err := publisher.startup()
if err != nil {
publisher.options.Logger.Infof("failed to startup publisher: %v", err)
continue
}
go publisher.startReturnHandler()
go publisher.startPublishHandler()
}
}

/*
Publish publishes the provided data to the given routing keys over the connection.
*/
Expand Down

0 comments on commit 05646d6

Please sign in to comment.