-1

How does one use the MessageReceiver.ReceiveAsync to retrieve sessionized messages in bulk?. My messages are written to the queue with SessionId. However I dont see any examples on how and where I should specify sessionid when I read messages in bulk. Is it possible to read sessionized messages in bulk using Microsoft.Azure.ServiceBus v5.1.2

Codecrasher99
  • 351
  • 3
  • 17

1 Answers1

0

If you want to get sessionized messages in bulk, you should use Azure.Messaging.ServiceBus package, just try the console app below:

using System;
using Azure.Messaging.ServiceBus;

namespace serviceBusTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectionString = "";
            string queueName = "";
            string sessionID = "";

            var client = new ServiceBusClient(connectionString);
           
            ServiceBusSessionReceiver receiver = client.AcceptSessionAsync(queueName, sessionID).GetAwaiter().GetResult();
            var messages = receiver.ReceiveMessagesAsync(maxMessages: 10).GetAwaiter().GetResult();
            foreach (var message in messages) {
                Console.WriteLine(message.Body);
            }

           
        }
    }
}

Result:

enter image description here

Stanley Gong
  • 11,522
  • 1
  • 8
  • 16