我需要通過“Azure 函數”讀取和處理來自 Azure 服務總線隊列的消息。消息應該以正確的順序處理,所以我需要避免并發調用。我為此使用了 Azure Function 服務總線觸發器(它是隊列的唯一訂閱者)。根據文檔,我將“servicebus/maxConcurrentCalls”(在 host.json 中)設置配置為 1。在此之上,我使用“Singleton”屬性裝飾了該函數。除此之外,消息似乎由不同的線程以隨機順序處理。我在這里想念什么?還是我誤會了什么?我使用的文檔:https : //github.com/Azure/azure-webjobs-sdk/wiki/Singleton主機.json:{ "serviceBus": { "maxConcurrentCalls": 1 }}天藍色功能:using System;using System.Threading.Tasks;using Microsoft.ServiceBus.Messaging;[Singleton]public static void Run(BrokeredMessage myQueueItem, TraceWriter log){ Stream stream = myQueueItem.GetBody<Stream>(); StreamReader reader = new StreamReader(stream); string messageContentStr = reader.ReadToEnd(); log.Info($"New TEST message: {messageContentStr} on thread {System.Threading.Thread.CurrentThread.ManagedThreadId}"); System.Threading.Thread.Sleep(2000); }這是日志的摘錄。如您所見,有不同的線程。并且,例如,“消息 19”出現在“消息 10”之前。是的,我確定我將消息按正確的順序放入隊列中。....2018-05-09T09:09:33.686 [Info] New TEST message: Message 19 on thread 332018-05-09T09:09:35.702 [Info] Function completed (Success, Id=007eccd0-b5db-466a-91c1-4f53ec5a7b3a, Duration=2013ms)2018-05-09T09:09:36.390 [Info] Function started (Id=b7160487-d10d-47a6-bab3-78da68a93498)2018-05-09T09:09:36.420 [Info] New TEST message: Message 10 on thread 39...
- 1 回答
- 0 關注
- 149 瀏覽
添加回答
舉報
0/150
提交
取消
