3
votes

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
I have a similar question; I receive a random number back instead of all of them; please see: stackoverflow.com/questions/28988477/…JosephDoggie
Does anyone know how to report this error to Microsoft; I tried but I couldn't find a readily-available link ....JosephDoggie
This still seems to be an issue. How has there not been any resolution!?creatiive
Not that I am aware ofJosephDoggie

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