0
votes

I am testing a project with a dead letter queue with Microsoft Service Bus. I send 26 messages (representing the alphabet) and I use a program that when receiving the messages, randomly puts some of them in a dead letter queue. The messages are always read in peek mode from the dead letter queue, so once they reach there they stay there. After running a few times, all 26 messages will be in the dead letter queue, and always remain there.

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

I use 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 which has a timeout, but this doesn't help, and proably only adds to the complexity.

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

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

This is mostly a testing example, but one would hope that "ReceiveBatch" would work in deterministic mode and not in a very (bad) random manner...

1
see also stackoverflow.com/questions/26862747/… not working as intended where a similar question is askedJosephDoggie
Does anyone know how to report this error to Microsoft; I tried but I couldn't find a readily-available link .... –JosephDoggie

1 Answers

0
votes

This is only a partial-answer or work-around; the following code reliably gets all elements, but doesn't use the "ReceiveBatch"; note, as far as I can discern, Peek(i) operates on a one-based index. Also: depending on which server one is running on, if you are charged by the message pull, this may (or may not) be more expensive, 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++;
            }