I'm reading messages from Azure Service Bus in my C# application. I'm reading them from Dead Letter Queue but I suppose it doesn't matter here. I need to read a block of messages of a given size, starting at a given offset (aka a page of messages).
I came up with the following, very inefficient, code:
SubscriptionClient client = SubscriptionClient.CreateFromConnectionString(
connectionString,
topic,
QueueClient.FormatDeadLetterPath(subscription));
var result = new List<string>();
for (var i = 0; i < offset + size; i++)
{
var msg = await client.PeekAsync();
if (msg == null)
{
return result;
}
if (i >= offset)
{
result.Add(msg);
}
}
return result;
Is there a way I can write this "seek" in a more efficient way?