brokeredmessage microsoft service bus queue ReceiveBatch not obtaining all dead letter messages

陌路散爱 提交于 2019-12-08 11:04:35

问题


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:


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++;
            }


来源:https://stackoverflow.com/questions/28988477/brokeredmessage-microsoft-service-bus-queue-receivebatch-not-obtaining-all-dead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!