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
Asked
Active
Viewed 92 times
1 Answers
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:

Stanley Gong
- 11,522
- 1
- 8
- 16
-
What about topics? Is there an option to subscribe and get topic messages in bulk? – Codecrasher99 Apr 01 '21 at 07:32
-
@Codecrasher99 you can find all code sample in this offical guide : https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-how-to-use-topics-subscriptions let me know if it helps :) – Stanley Gong Apr 02 '21 at 02:52
-
@Codecrasher99 How's going? Has your issue got resolved? – Stanley Gong Apr 08 '21 at 07:07