[英]How mark a Service Bus message as processed from an Azure function?
I have two very simple NodeJS based Azure function, one which pushes an event to a Service Bus queue:我有两个非常简单的基于 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!');
}
and an another which reads the message, logs it's content and then exists:另一个读取消息,记录其内容然后存在:
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();
}
The related parts from my host.json
:我的
host.json
的相关部分:
{
"extensions": {
"serviceBus": {
"prefetchCount": 100,
"messageHandlerOptions": {
"autoComplete": false,
"maxConcurrentCalls": 512,
"maxAutoRenewDuration": "00:10:00"
}
}
},
}
What I would expect that calling the first function once would result in:我期望调用第一个函数一次会导致:
However what I see instead is the second function re-receives the message from the queue until DeliveryCount
reaches the limit.然而,我看到的是第二个函数从队列中重新接收消息,直到
DeliveryCount
达到限制。
My questions are:我的问题是:
According to the host.json you provided, you set the autoComplete
as false.根据您提供的 host.json,您将
autoComplete
设置为 false。 If you want to mark the message as complete
, we need to manually call the method complete()
.如果要将消息标记为
complete
,我们需要手动调用方法complete()
。 For more details, please refer to the docuemnt更多详情,请参考文档
But according to my research, at the moment, the autoComplete: false
is only useful for C# function.但根据我的研究,目前
autoComplete: false
仅对 C# 函数有用。 For more details, please refer to the GitHub issue .更多详情请参考GitHub issue 。 So I suggest you set the
autoComplete
as true.所以我建议你将
autoComplete
设置为 true。 It will call Complete
on the message if the function finishes successfully, or calls Abandon
if the function fails.如果函数成功
Complete
,它将在消息上调用Complete
,如果函数失败,它将调用Abandon
。 For more details, please refer to the official document更多详情请参考官方文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.