0

Here is what I am trying to achieve :

  1. On the service bus I have a topic which contains 5005 messages.

  2. I need to peek all the messages without completing them and add them to a list (List<BrokeredMessage>)

Here is what I am trying :

IEnumerable<BrokeredMessage> dlIE = null;
List<BrokeredMessage> bmList = new List<BrokeredMessage>();
long i = 0;
while (i < count) //count is the total messages in the subscription
 {
  dlIE = deadLetterClient.ReceiveBatch(100);
  bmList.AddRange(dlIE);
  i = i + dlIE.Count();
 }

In the above code I can only fetch 100 messages at a time since there is a batch size limit to retrieving the messages.

I have also tried to do asynchronously but it always returns 0 messages in the list. This is the code for that:

static List<BrokeredMessage> messageList = new List<BrokeredMessage>();
long i = 0;          
 while (i < count)
            {
                var task = ReceiveMessagesBatchForSubscription(deadLetterClient);
                i = i + 100;
            }
            Task.WaitAny();



public async static Task ReceiveMessagesBatchForSubscription(SubscriptionClient deadLetterClient)
        {
            while (true)
            {
                var receivedMessage = await deadLetterClient.ReceiveBatchAsync(100);
                messageList.AddRange(receivedMessage);
            }
        }

Can anyone please suggest a better way to do this?

nitinvertigo
  • 1,180
  • 4
  • 32
  • 56
  • Just checking because of your variable name, but are you intending to retrieve messages from the dead letters, rather than the "main" topic client? If nothing ever goes wrong, your dead letters will always be empty. – S. Baggy Nov 05 '15 at 22:07
  • My original requirement is to retrieve messages from dead letter queue. But for testing purpose I changed the path to topic since both the methods will be the same but forgot to change the variable name – nitinvertigo Nov 06 '15 at 07:46

0 Answers0