Azure 佇列儲存體踩坑紀錄

阿蘇卡
3 min readAug 3, 2020

--

上次使用表格儲存體踩坑之後,沒想到佇列儲存體更新 SDK 也遇坑…..

故事是這樣開始的:

為了使用 Azure Queue,於 ASP.Net Core Web App 中引用 WindowsAzure.Storage 套件,並包裝成 Service 供注入使用:

配合 Azure Queue Trigger Function V3,觸發處理,簡單寫一個範例:

使用了一段時間都很順利,直到微軟宣布棄用 WindowsAzure.Storage,改版為 Azure.Storage.Queues

因此,參照 MSDN 上範例寫了一版新的 Service,沒想到,事情沒有這麼簡單...

問題:Azure Queue Trigger Function 顯示編碼錯誤

送一個純文字訊息至 Queue 中:"TEST"

使用 Azure.Storage.Queues 送出訊息,會收到以下錯誤訊息:

System.Private.CoreLib: Exception while executing function: TestQueueFunction. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'myQueueItem'. System.Private.CoreLib: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

翻譯一下,簡單來說就是 Azure Function 認為這不是合法的 Base64 字串。
也就是說,Azure.Storage.Queues 沒有在送出文字前先將內容做 Base64 編碼,導致 Azure Function 無法識別。

這個問題已經有人反映(Issue 狀態請參照此連結),但目前只能先自行加入編碼處理囉

private static string Base64Encode(string plainText){var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);return System.Convert.ToBase64String(plainTextBytes);}

修改後完整程式碼如下:

心得:SDK 版更,要小心謹慎啊

[2020/08/04 補充]追蹤 Azure Function 使用的 Storage 套件版本,為 Microsoft.Azure.WebJobs.Extensions.Storage,而其引用的是舊版的 WindowsAzure.Storage

嗯.....可能要等 Microsoft.Azure.WebJobs.Extensions.Storage 改用 Azure.Storage.Queues 才能從根本修正問題吧?

--

--

阿蘇卡
阿蘇卡

Written by 阿蘇卡

後端工程師。記錄下自己開發路上踩過的坑、研究過後的心得,希望對自己好,對其他工程師也好~

No responses yet