In an Azure Service Bus Topic I have a subscription with more than 1000 messages. These messages are consumed by a worker role. For monitoring purposes, I want to peek first 10 messages, to see what kind of messages are waiting to be processed. To accomplish that task I create a subscriptionclient and I call method PeekBatchAsync . The strange behavior is that sometimes PeekBatchAsync returns less than 10 messages (i.e. 2 or 4 messages).
Code Example :
Dim subscriptionClient As SubscriptionClient = messagingFactory.CreateSubscriptionClient(topicName, subscriptionName)
Dim messages = Await subscriptionClient.PeekBatchAsync(10)
More information to clarify the context:
- I am sure that the subscription contains more than 1000 messages
- The topic was created with EnablePartitioning = True
- I'm using library Microsoft.ServiceBus v. 2.3.4.0
- I'm using sessions
- The most of the time I got the right number of messages (10) and sometimes I got less messages. I can't figure out what are the exact conditions to replicate the issue
My question is : Why sometimes the method returns less messages than expected?