MessageReceiver.ReceiveBatch () not working as expected

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

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

      

I have verified that my queue contains 20 messages using the Service Bus explorer.

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

+3


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"; notice, as far as I can tell, Peek (i) works with a single index. Also: depending on what server it is running on, if you are charging 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