我需要通過“Azure 函數(shù)”讀取和處理來自 Azure 服務(wù)總線隊(duì)列的消息。消息應(yīng)該以正確的順序處理,所以我需要避免并發(fā)調(diào)用。我為此使用了 Azure Function 服務(wù)總線觸發(fā)器(它是隊(duì)列的唯一訂閱者)。根據(jù)文檔,我將“servicebus/maxConcurrentCalls”(在 host.json 中)設(shè)置配置為 1。在此之上,我使用“Singleton”屬性裝飾了該函數(shù)。除此之外,消息似乎由不同的線程以隨機(jī)順序處理。我在這里想念什么?還是我誤會了什么?我使用的文檔:https : //github.com/Azure/azure-webjobs-sdk/wiki/Singleton主機(jī).json:{ "serviceBus": { "maxConcurrentCalls": 1 }}天藍(lán)色功能: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”出現(xiàn)在“消息 10”之前。是的,我確定我將消息按正確的順序放入隊(duì)列中。....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 關(guān)注
- 138 瀏覽
添加回答
舉報(bào)
0/150
提交
取消