Skip to content

Commit

Permalink
victors requests - one flag for notify return
Browse files Browse the repository at this point in the history
  • Loading branch information
wagslane committed Sep 6, 2021
1 parent 3c30293 commit b89627c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func WithPublishOptionsHeaders(headers Table) func(*PublishOptions) {
type Publisher struct {
chManager *channelManager

notifyReturnChan chan Return
shouldNotifyReturn bool
notifyReturnChan chan Return

disablePublishDueToFlow bool
disablePublishDueToFlowMux *sync.RWMutex
Expand Down Expand Up @@ -154,17 +153,17 @@ func NewPublisher(url string, config amqp.Config, optionFuncs ...func(*Publisher
disablePublishDueToFlow: false,
disablePublishDueToFlowMux: &sync.RWMutex{},
logger: options.Logger,
notifyReturnChan: make(chan Return),
shouldNotifyReturn: false,
notifyReturnChan: nil,
}

go func() {
go publisher.startNotifyFlowHandler()
go publisher.startNotifyFlowHandler()

// restart notifiers when cancel/close is triggered
go func() {
for err := range publisher.chManager.notifyCancelOrClose {
publisher.logger.Printf("publish cancel/close handler triggered. err: %v", err)
go publisher.startNotifyFlowHandler()
if publisher.shouldNotifyReturn {
if publisher.notifyReturnChan != nil {
go publisher.startNotifyReturnHandler()
}
}
Expand All @@ -176,7 +175,8 @@ func NewPublisher(url string, config amqp.Config, optionFuncs ...func(*Publisher
// NotifyReturn registers a listener for basic.return methods.
// These can be sent from the server when a publish is undeliverable either from the mandatory or immediate flags.
func (publisher *Publisher) NotifyReturn() <-chan Return {
publisher.shouldNotifyReturn = true
publisher.notifyReturnChan = make(chan Return)
go publisher.startNotifyReturnHandler()
return publisher.notifyReturnChan
}

Expand Down

0 comments on commit b89627c

Please sign in to comment.