Azure / azure-functions-servicebus-extension

Service Bus extension for Azure Functions
MIT License
65 stars 35 forks source link

Fix PeekAsync for ServiceBusScaleMonitor #121

Closed wenhzha closed 3 years ago

wenhzha commented 3 years ago

As suggested by Service Bus team in the service bus runtime driven scaling investigation (ICM ticket),

message = await _receiver.Value.PeekAsync()

intends to peek the first message . However, in this usage, the client remembera the sequence number of the last message and peeks the next message on the next call. For example, if there are two messages in the queue, calling peekAsync returns the first message. If you call peekAsync again, it returns the second message. If you call peekAsync again, it will return no message or null.

Use PeekBySequenceNumberAsync instead so it forces the client to check the first message from sequence number =0.

Repro:

  1. drop two message on the service bus queue/topic
  2. reuse the service bus message receiver and call peek async three times

Repro-ed and verified the PeekBySequenceNumberAsync would switch to the desired behavior.

Pull request checklist

mathewc commented 3 years ago

Thanks for the investigation and fix @wenhzha!