Quantcast
Channel: Service Bus forum
Viewing all articles
Browse latest Browse all 1916

Azure Service bus MessageReceiver.ReceivAsync returns null

$
0
0

I have an azure function that is triggered every 1 minute. The function creates a MessageReceiver like this

var messageReceiver = new MessageReceiver(serviceBusConnectionString, entityPath, ReceiveMode.PeekLock, null, 0);

The subscription has a lock duration of 1 minute. It then tries to fetch up to 100 messages from the subscription like this:

var allMessages = new List<Message>();
Message message;

do {
    message = await messageReceiver.ReceiveAsync(TimeSpan.FromSeconds(5));
    if (message != null) allMessages.Add(message);
} while (message != null && allMessages.Count() < 100);

After processing the messages are completed using messageReceiver.CompleteAsync and the messageReceiver is closed using messageReceiver.CloseAsync().

The first time the function runs it fetches up to several messages from the subscription, but on the next runs it often only fetches 0 or 1 message no matter the number of messages available in the subscription (Service Bus Explorer shows that there > 10 messages in the subscription). So it seems that ReceiveAsync returns null even when there is messages available.

Increasing the timeout for ReceiveAsync doesn't seem to help.

Why does ReceiveAsync return null when there is messages available?


Viewing all articles
Browse latest Browse all 1916

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>