Azure Function V2 Service Bus Message Deferral(Azure Function V2 服务总线消息延迟)
问题描述
我正在尝试将我的 v1 函数转换为 v2 函数,但我找不到延迟消息的替代方法.
I am attempting to convert my v1 function to a v2 function, but I cannot find a replacement for deferring a message.
在 Azure Functions V1 中,它是 BrokeredMesage
上的一个方法,称为 .DeferAsync()
.在 V2 中不再有 BrokeredMessage
而是只有一个 Microsoft.Azure.ServiceBus.Message
并且不包含 .DeferAsync()
.
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()
.
根据 docs:
API 在 .NET Framework 客户端中为 BrokeredMessage.Defer 或 BrokeredMessage.DeferAsync,在 .NET Standard 客户端中为 MessageReceiver.DeferAsync,在 Java 客户端中为 messageReceiver.defer 或 messageReceiver.deferSync.
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.
但是我怎样才能访问 MessageReciever?这是我的函数的一个示例:
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
}
那么有谁知道如何推迟从 Azure 服务总线触发的 V2 Message
?
So does anyone know how to defer a V2 Message
that is triggered from the Azure Service Bus?
推荐答案
正如您所提到的,新的消息接收器提供了一个异步延迟方法,您可以使用以下代码将其添加到您的函数中:
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);
}
这篇关于Azure Function V2 服务总线消息延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Azure Function V2 服务总线消息延迟
- C# 中多线程网络服务器的模式 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01