hi Michael!
thanks for posting this, it's a tricky one for sure ))
when u call receivemessagesasync, azure queue storage actually does two things at once: it gets the messages AND makes them invisible for a short time (by default 30 seconds). but in ur case, something's going wrong in this process )) let's check the basics. u're using the right approach with approximatecount, but there's a sneaky thing, this count isn't always 100% accurate. microsoft docs even say it's... well, approximate :) microsoft docs link
now about ur disappearing messages, this usually happens when
the visibility timeout expires before u process the message
someone else is also reading the same queue
there's some network hiccup during the operation
try this fix add a small delay after getting the count. sometimes the queue needs a moment to sync up. also, set a longer visibility timeout just to be safe.
var options = new queuereceivemessagesoptions
{
visibilitytimeout = timespan.fromminutes(5) // give urself more time
};
var messages = await queueclient.receivemessagesasync(maxmessages: count, options: options);
if that doesn't help, maybe add some retry logic. azure storage can sometimes be flaky, especially under heavy load. microsoft suggests using their built-in retry policies, retry policy docs
one more thing, check if u have multiple instances of ur webjob running. if two instances grab the same message at nearly the same time... poof! message disappears :))
try these tweaks and let me know how it goes %)
Best regards,
Alex
and "yes" if you would follow me at Q&A - personaly thx.
P.S. If my answer help to you, please Accept my answer
PPS That is my Answer and not a Comment