Azure Function V2服务总线消息延迟

编程入门 行业动态 更新时间:2024-10-10 18:27:24
本文介绍了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客户端中为mesageReceiver.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 Service Bus触发的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服务总线消息延迟

本文发布于:2023-11-14 06:11:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586442.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:总线   消息   Azure   Function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!