Azure Function V2 Service Bus Message Deferral

跟風遠走 提交于 2019-12-23 19:24:55

问题


I am attempting to convert my v1 function to a v2 function, but I cannot find a replacement for deferring a message.

In V1 of Azure Functions it was a method on the BrokeredMesage called .DeferAsync(). In V2 there is no longer a BrokeredMessage but just a Microsoft.Azure.ServiceBus.Message and this does not contain the method of .DeferAsync().

According to the docs:

The API is BrokeredMessage.Defer or BrokeredMessage.DeferAsync in the .NET Framework client, MessageReceiver.DeferAsync in the .NET Standard client, and mesageReceiver.defer or messageReceiver.deferSync in the Java client.

But how can I get access to the MessageReciever? Here is an example of my function:

[FunctionName("MyFunction")]
public static void Run([ServiceBusTrigger("topic", "subscription", Connection = "AzureServiceBusPrimary")]Message message, ILogger log)
{
    //Code
}

So does anyone know how to defer a V2 Message that is triggered from the Azure Service Bus?


回答1:


As you mention, the new message receiver offers an async defer method and you can add this to your function by using the following code:

[FunctionName("MyFunction")]
public static async Task Run([ServiceBusTrigger("topic", "subscription", Connection = "AzureServiceBusPrimary")]Message message, string lockToken, MessageReceiver messageReceiver, ILogger log)
{
    //Your function logic
    await messageReceiver.DeferAsync(lockToken);
}


来源:https://stackoverflow.com/questions/56439156/azure-function-v2-service-bus-message-deferral

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!