MessageReceiver.ReceiveBatch() not working as intended

筅森魡賤 提交于 2019-12-10 20:53:15

问题


I am trying to receive messages in batch from the ServiceBus using the ReceiveBatch method in the MessageReceiver:

IEnumerable<BrokeredMessage> messages;
var messagingfactory = MessagingFactory.CreateFromConnectionString("ConnectionString");
var msgrcvr = messagingfactory.CreateMessageReceiver("queueName", ReceiveMode.ReceiveAndDelete);
messages = msgrcvr.ReceiveBatch(20, timeoutInSecs);

I have checked that my queue contains 20 messages using the Service Bus Explorer.

This code returns only one message in the messages structure. Is there some property I am missing?


回答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/26862747/messagereceiver-receivebatch-not-working-as-intended

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