简体   繁体   English

如何将服务总线消息标记为从 Azure 函数处理?

[英]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:我期望调用第一个函数一次会导致:

  • one message is pushed to the service bus queue (works)一条消息被推送到服务总线队列(有效)
  • the second function would read that message (works)第二个函数将读取该消息(有效)
  • the second function would marke it as processed when exiting without error (doesn't work)第二个函数会在无错误退出时将其标记为已处理(不起作用)

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:我的问题是:

  • Why the task is not marked as complete automatically when the task is finished?为什么任务完成后没有自动标记为完成?
  • How can I mark it as complete manually if messages are not marked as finished by default?如果邮件默认未标记为已完成,如何手动将其标记为完成?

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.

相关问题 azure功能服务总线输出消息属性 - azure function service bus output message properties 如何从NodeJS中的单个azure函数向azure服务总线和事件发送消息到事件集线器总线? - How to send a message to azure service bus & event to event hub bus from single azure functions in NodeJS? 如何从Azure移动服务脚本向Azure服务总线队列发送消息 - How to send a message to Azure service bus queue from a Azure mobile services script 在Node.js Azure函数中检索Service Bus消息的属性 - Retrieve properties of Service Bus message in Node.js Azure Function 如何使用 Azure 函数绑定发送预定的服务总线队列消息? - How to use an Azure Function Binding to send a scheduled Service Bus Queue message? 使用 NodeJS 将服务总线队列中的消息从被处理延迟到预定时间 - Delay a message in the Service Bus Queue from being processed until a scheduled time with NodeJS 从 POSTMAN nodeJs 向 Azure 服务总线发送消息 - Sending message to Azure Service Bus from POSTMAN nodeJs Azure 服务总线消息锁定和消息完成 - Azure service bus message lock and message completion 如何在Node.js中异步接收Azure服务总线消息 - How to asynchronously receive a azure service bus message in node.js NodeJS @azure/service-bus:如何更新消息的锁 - NodeJS @azure/service-bus: How to renewLock for a message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM