Azure Strage中的Queue機制

Storage Queue是相對Service Bus而言較為簡單便宜的queue解決方案,以Storage為儲存體,在Storage中就可以直接建立:
圖片

透過程式碼操作的方式也很簡單,先找到key:
圖片

接著透過SDK,建立一個QueueClient物件即可操作:

        public static void CreateQueueClient(string queueName)
        {
            // Get the connection string from app settings
            string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];

            // Instantiate a QueueClient which will be used to create and manipulate the queue
            QueueClient queueClient = new QueueClient(connectionString, queueName);
        }

請注意上面的程式碼使用了 Azure.Storage.Queues 套件,因此你必須從nuget安裝:

dotnet add package Azure.Storage.Queues

我在github上有一個範例,讀者可以在建立好queue之後,透過git clone下載該範例運行:

git clone https://github.com/isdaviddong/az204-DemoAzureStorageQueue.git

運行的流程請看底下展示影片:

身為一個簡簡單單的FIFO容器,Queue看起來沒啥大錄用,不過就是放放資料讓資料排隊慢慢處理,但記得前面提過的 Load Leveling嗎:

(from Microsoft architecture center)

如果用的好,Queue可以幫你省下大筆 做 scale out的經費呢,總有人覺得雲端貴,但其實,往往是差在知不知道怎麼使用而已。

ref: https://learn.microsoft.com/en-us/azure/architecture/patterns/queue-based-load-leveling

留言

這個網誌中的熱門文章

在POC或迷你專案中使用 LiteDB

使用Qdrant向量資料庫實作語意相似度比對

專業的價值...

讓 LINE Bot 對談機器人顯示 "Loading..." 動畫

使用 Airtable 在小型需求上取代傳統資料庫