Skip to content

Commit

Permalink
remove unnecessary nil check and update debug log
Browse files Browse the repository at this point in the history
Signed-off-by: Joni Collinge <[email protected]>
  • Loading branch information
jjcollinge committed Jul 20, 2022
1 parent 517b6e0 commit 58628ef
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions internal/component/azure/servicebus/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,6 @@ func (s *Subscription) handleAsync(ctx context.Context, msg *azservicebus.Receiv
go func() {
var consumeToken bool
var err error
var messageKey int64

// We check for the existence of the sequence number again just in case
// it has been unset by some other goroutine and we cannot process the message.
if msg.SequenceNumber == nil {
s.logger.Errorf("Message has no sequence number: %s", msg.MessageID)
s.AbandonMessage(ctx, msg)
}
messageKey = *msg.SequenceNumber

// If handleChan is non-nil, we have a limit on how many handler we can process
limitConcurrentHandlers := cap(s.handleChan) > 0
Expand All @@ -231,7 +222,7 @@ func (s *Subscription) handleAsync(ctx context.Context, msg *azservicebus.Receiv
}

// Remove the message from the map of active ones
s.removeActiveMessage(messageKey)
s.removeActiveMessage(*msg.SequenceNumber)

// Remove an entry from activeMessageChan to allow processing more messages
<-s.activeMessagesChan
Expand Down Expand Up @@ -330,18 +321,18 @@ func (s *Subscription) CompleteMessage(ctx context.Context, m *azservicebus.Rece
}

func (s *Subscription) addActiveMessage(m *azservicebus.ReceivedMessage) error {
s.logger.Debugf("Adding message %s to active messages on %s", m.MessageID, s.entity)
if m.SequenceNumber == nil {
return fmt.Errorf("message sequence number is nil")
}
s.logger.Debugf("Adding message with sequence number %d to active messages on %s", *m.SequenceNumber, s.entity)
s.mu.Lock()
s.activeMessages[*m.SequenceNumber] = m
s.mu.Unlock()
return nil
}

func (s *Subscription) removeActiveMessage(messageKey int64) {
s.logger.Debugf("Removing message %s from active messages on %s", messageKey, s.entity)
s.logger.Debugf("Removing message with sequence number %d from active messages on %s", messageKey, s.entity)
s.mu.Lock()
delete(s.activeMessages, messageKey)
s.mu.Unlock()
Expand Down

0 comments on commit 58628ef

Please sign in to comment.