Search code examples
azureazure-storageazure-queuesazure-storage-queues

Creating a Azure.Storage.Queues client that can handle multiple queues


I'm migrating my code from Microsoft.WindowsAzure.Storage.Queue to Azure.Storage.Queues. In my app, I wrapped all queue operations I use in a MyQueueClient class. The old way of creating a queue client was as follows:

CloudStorageAccount account = CloudStorageAccount.Parse(ConnectionString);
CloudQueueClient client = account.CreateCloudQueueClient();

Because I have multiple queues, this approach worked nicely for me. In the new approach, it looks like I need to pass the queue name as one of the parameters to create a queue client -- see documentation: https://learn.microsoft.com/en-us/azure/storage/queues/storage-dotnet-how-to-use-queues?tabs=dotnet#create-the-queue-service-client

QueueClient queueClient = new QueueClient(connectionString, queueName);

So, I'm a bit confused here. Does this mean, I have to create a separate queue client for each queue that I work with? Say, I have 3 queues, does it mean I have to create 3 queue clients? Doesn't seem to make sense. What am I missing here?


Solution

  • You can use the code below:

            QueueServiceClient queueServiceClient = new QueueServiceClient(connectionString);
    

    then you can use the methods based on queueServiceClient(note that it may have some limitations compared to the old one).

    enter image description here