簡體   English   中英

有沒有更好的方法來列出 C# 中的 Azure 存儲帳戶中的隊列?

[英]Is there a better way to List Queues in an Azure Storage Account in C#?

我一直在嘗試獲取 C# 中 Azure 存儲帳戶中的所有隊列。我一直在嘗試使用此處顯示的 API 端點:

https://learn.microsoft.com/en-us/rest/api/storageservices/list-queues1

但它似乎非常古老。 它不支持不記名令牌,而是需要一個 SharedKey,我發現生成 SharedKey 的代碼也很舊,可以在此處找到(在示例應用程序中):

https://learn.microsoft.com/en-us/azure/storage/common/storage-rest-api-auth

在我開始執行此操作之前,我想問問是否有人知道更好/更新的方法來獲取給定 Azure 存儲帳戶中所有隊列的列表?

您可以使用 .NET 的Azure 存儲隊列客戶端庫來執行此類管理操作。

QueueServiceClient class 有一個方法GetQueues將列出帳戶中的所有隊列,請參閱文檔

您可以使用以下代碼使用 C# 列出 Azure 存儲帳戶中的隊列。

QueueServiceClient serviceClient = new QueueServiceClient(conn_str);
        
        //list all queues in the storage account
        var myqueues = serviceClient.GetQueues().AsPages();

        //then you can write code to list all the queue names          
        foreach (Azure.Page<QueueItem> queuePage in myqueues)
        {
            foreach (QueueItem q in queuePage.Values)
            {
                Console.WriteLine(q.Name);
            }

        }

        //get a queue client
        var myqueue_client = serviceClient.GetQueueClient("the queue name");

有關更多信息,您可以參考此鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM