[英]How mark a Service Bus message as processed from an Azure function?
我有兩個非常簡單的基於 NodeJS 的 Azure 函數,一個將事件推送到服務總線隊列:
import { Context } from '@azure/functions';
export async function run(context: Context, myTimer: any): Promise<void> {
context.log('Function started!');
context.bindings.taskQueue2 = [{ message: 'Some task message' }];
context.log('Function finished!');
}
另一個讀取消息,記錄其內容然后存在:
import { Context } from '@azure/functions';
export async function run(context: Context, myQueueItem: any): Promise<void> {
// https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus#trigger---message-metadata
context.log('Node.js ServiceBus queue trigger function processed message', myQueueItem);
context.log('EnqueuedTimeUtc =', context.bindingData.enqueuedTimeUtc);
context.log('ExpiresAtUtc =', context.bindingData.expiresAtUtc);
context.log('DeliveryCount =', context.bindingData.deliveryCount);
context.log('MessageId =', context.bindingData.messageId);
// I have tried with both calling and not calling context.done
// context.done();
}
我的host.json
的相關部分:
{
"extensions": {
"serviceBus": {
"prefetchCount": 100,
"messageHandlerOptions": {
"autoComplete": false,
"maxConcurrentCalls": 512,
"maxAutoRenewDuration": "00:10:00"
}
}
},
}
我期望調用第一個函數一次會導致:
然而,我看到的是第二個函數從隊列中重新接收消息,直到DeliveryCount
達到限制。
我的問題是:
根據您提供的 host.json,您將autoComplete
設置為 false。 如果要將消息標記為complete
,我們需要手動調用方法complete()
。 更多詳情,請參考文檔
但根據我的研究,目前autoComplete: false
僅對 C# 函數有用。 更多詳情請參考GitHub issue 。 所以我建議你將autoComplete
設置為 true。 如果函數成功Complete
,它將在消息上調用Complete
,如果函數失敗,它將調用Abandon
。 更多詳情請參考官方文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.