Search code examples
azure-functionsazureservicebusazure-servicebus-subscriptions

What happened to CompleteAsync and AbandonAsync method for ServiceBusTriggers in Azure Functions 2.0


I could implement something similar to the following in Azure Functions 1.0, but now it seems with 2.0 CompleteAsync() and AbandonAsync() are no longer available.

[FunctionName("Process")]
public static async System.Threading.Tasks.Task RunAsync(
    [ServiceBusTrigger(
        "%ServiceBus.Topic%", "%ServiceBus.Subscription%",
        Connection = "AzureWebJobsServiceBus")]Message message, ILogger log) {
    try {
        MyMessageModel messageModel = message.GetBody<MyMessageModel>();
        await DoAllTheThingsAsync().ConfigureAwait(false);                
        await message.CompleteAsync().ConfigureAwait(false);
    } catch {
        await message.AbandonAsync().ConfigureAwait(false);
        throw;
    }
}

Has control been relinquished to the Azure Function default for Peek Lock?


Solution

  • Azure Function 1.X used WindowsAzure.ServiceBus library for processing message. There, the methods like CompleteAsync() and AbandonAsync() were available with the BrokeredMessage object received by the Function.

    Where in Functions of version 2.X, Microsoft.Azure.ServiceBus library is being used, here BrokeredMessage is replaced by Message object, where no such methods are available. They are available only under QueueClient.