azure-service-bus icon indicating copy to clipboard operation
azure-service-bus copied to clipboard

Paging through a considerable amount of queues in a namespace results in inconsistent page- and total item count results

Open sergevm opened this issue 6 months ago • 5 comments

Description

I have been building a little service bus explorer tool that runs on the major operating systems, and that has proven useful in my day job. The tool is using the Azure.Messaging.Servicebus nuget package to work on messages etc., but also to list and manage storage resources. One of the features that is very helpful, is the ability to filter on queue / topic / subscription names.

Older SDK packages (predecessors), which supported server-side filtering, are deprecated, and unfortunately the current SDK does not support server-side filtering, so I had to fall back to client side filtering instead.

Unfortunately, I found that, in case of a namespace with a lot of queues e.g. (+1900 in my case), the AsyncPageable result does not provide consistent pagination results: both the number of pages returned and the total number of resources (queues e.g.) varies on subsequent runs, which makes the search results inconsistent.

I got a suggestion to use Azure.ResourceManager.Servicebus, but it exposes the same behavior it seems. To verify this, I used a minimal console app, where I simply list and count the queues in a namespace:

// See https://aka.ms/new-console-template for more information

using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.ServiceBus;

var armClient = new ArmClient(new InteractiveBrowserCredential(
    "[TENANT ID]",
    "[ENTRA APP ID]",
    new InteractiveBrowserCredentialOptions
    {
        RedirectUri = new Uri("http://localhost")
    }));

var namespaceResource = armClient.GetServiceBusNamespaceResource(new ResourceIdentifier($"/subscriptions/[SUB ID]/resourceGroups/[RG ID]/providers/Microsoft.ServiceBus/namespaces/[NS NAME]"));
var asyncPageable = namespaceResource.GetServiceBusQueues().GetAllAsync();
var count = 0;
await foreach (var queue in asyncPageable)
{
    count++;
    Console.WriteLine(queue.Data.Name);
}

Console.WriteLine($"Total queues: {count}");

Actual Behavior

  1. Subsequent runs show a different count of queues

Expected Behavior

  1. Subsequent runs show a consistent count of queues

sergevm avatar Dec 31 '23 09:12 sergevm