Brokeredmessage microsoft service bus queue ReceiveBatch does not receive all dead letter messages

I am testing a dead letter project using Microsoft Service Bus. I am posting 26 messages (representing the alphabet) and I am using a program that, when receiving messages, randomly puts some of them in a dead letter queue. Messages are always read in peek mode from the dead letter queue, so once they get there, they stay there. After starting several times, all 26 messages will be in the dead letter queue and always remain there.

However, when reading them, sometimes only a few are read (for example, 6), sometimes all 26.

I am using the command:

const int maxToRead = 200; // It seems one wants to set this higher than    
                          // the anticipated load, obtaining only some back
IEnumerable<BrokeredMessage> dlIE = 
            deadletterSubscriptionClient.ReceiveBatch(maxToRead);

      

There is an overload of ReceiveBatch that has a timeout, but that doesn't help and only makes it easier to add complexity.

Why doesn't it get all 26 messages every time, since it is used in "peek" mode and the messages stay there.

I can use the "Service Bus Explorer" to actually confirm that all messages are in the error queue and remain there.

This is mainly a test case, but one would hope that "ReceiveBatch" would work in a deterministic manner, not very (randomly) ...

0


source to share


1 answer


This is only a partial answer or workaround; the following code reliably receives all the elements, but does not use "ReceiveBatch"; note, as far as I can tell, Peek (i) works with a single index. Also: depending on which server it is running on, if you are charged by message pull, it may (or may not be) more costly, so use at your own risk:



            List<BrokeredMessage> dlIE = new List<BrokeredMessage>();

            BrokeredMessage potentialMessage = null;
            int loopCount = 1;
            while ((potentialMessage = deadletterSubscriptionClient.Peek(loopCount)) != null)
            {
                dlIE.Add(potentialMessage);
                loopCount++;
            }

      

0


source







All Articles