0
votes

I have two very simple NodeJS based Azure function, one which pushes an event to a Service Bus queue:

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:

{
  "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.

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?
1
So you want to mark the message as processed?George Chen
Yes, basically. However from reading the docs, especially the explanation of messageHandlerOptions.autoComplete I would expect that I don’t have to do it manually, just return from my function without raising an error.NoNameProvided

1 Answers

0
votes

According to the host.json you provided, you set the autoComplete as false. If you want to mark the message as complete, we need to manually call the method complete(). For more details, please refer to the docuemnt enter image description here

But according to my research, at the moment, the autoComplete: false is only useful for C# function. For more details, please refer to the GitHub issue. So I suggest you set the autoComplete as true. It will call Complete on the message if the function finishes successfully, or calls Abandon if the function fails. For more details, please refer to the official document