简体   繁体   English

Azure function 服务总线触发器设置从 function 级别自动完成

[英]Azure function service bus trigger set autocomplete from function level

In Azure function app I am using a service bus trigger to read messages.在 Azure function 应用程序中,我使用服务总线触发器来读取消息。

[FunctionName("Function1")]
public static async Task<Message> Run([ServiceBusTrigger("myqueue", Connection = "queueconnection")] Message myQueueItem, MessageReceiver messageReceiver, ILogger log)

So there are two options of read auto complete and peek lock.所以有read auto complete和peek lock两种选择。 I am able to control this from host.josn using below configurations.我可以使用以下配置从host.josn控制它。

{
"version": "2.0",
"extensions": {
    "serviceBus": {
        "messageHandlerOptions": {
            "autoComplete": false
        }
    }
 }
}

But if I do this in host.json this is applicable for function app and effect all the functions deployed in that function app.但是,如果我在 host.json 中执行此操作,则这适用于 function 应用程序并影响部署在该 function 应用程序中的所有功能。 So I want to know if below options are possible,If yes how it can be achieved.所以我想知道以下选项是否可行,如果可以,如何实现。

  1. Having auto complete property in function it self where we configure ServiceBusTrigger.在 function 中具有自动完成属性,它在我们配置 ServiceBusTrigger 的地方自行完成。
  2. If it can be set in function level, making it configurable by moving the property to function app Configurations.如果它可以在 function 级别设置,通过将属性移动到 function 应用程序配置使其可配置。

Default Syntax Format of Azure Functions Service Bus Trigger is like: Azure 函数服务总线触发器的默认语法格式如下:

[FunctionName("ServiceBusQueueTriggerCSharp")] public static void Run( [ServiceBusTrigger("myqueue", Connection = "ServiceBusConnection")] ... )

Here myqueue is the Queue Name declared at the Function Level in the Azure Function.这里的myqueue是Azure Function中886982359588级别声明的Queue Name

In the same way, we have many attributes (properties) including AutoComplete can be used in the Function Level , that you can refer here to see the more information on Service Bus Trigger Function Level Properties and its functionality.同样的,我们有很多属性(properties)包括AutoComplete都可以在Function Level中使用,你可以参考这里查看 Service Bus Trigger Function Level Properties 及其功能的更多信息。

If the Azure Function Stack belongs to .NET Core 3.1, then configure the AutoComplete option manually in FunctionsStartup file, the syntax is like:如果 Azure Function Stack 属于 .NET Core 3.1,则在FunctionsStartup文件中手动配置AutoComplete选项,语法如下:

builder.Services.Configure(delegate(ServiceBusOptions options)
{
    options.MessageHandlerOptions.AutoComplete = false;
});

Refer here for more information on configuring AutoComplete option manually.有关手动配置自动完成选项的更多信息,请参阅此处

If the Azure Function Stack belongs to greater than .NET Core 3.1, then configure the AutoComplete option at the Function Level in the ServiceBusTrigger Function Class like:如果 Azure 886982359588 Stack 属于大于 .NET Core 3.1,则在ServiceBusTrigger Function Class Function AutoComplete

[FunctionName("ProcessMessage")] 
public async Task Run( 
// Setting AutoComplete to true (the default) processes the message non-transactionally 
[ServiceBusTrigger("ProcessMessage", AutoCompleteMessages = true)] ServiceBusReceivedMessage message, ILogger logger, ExecutionContext executionContext) 
{ 
await endpoint.ProcessNonAtomic(message, executionContext, logger); 
}

Setting AutoComplete to false processes the message transactionally将 AutoComplete 设置为 false 以事务方式处理消息

Refer here , provides the information on ( AutoComplete , AutoCompleteMessages ) naming differentiation based on Function Extension Version.参考这里,提供了基于 Function Extension Version 的 ( AutoComplete , AutoCompleteMessages ) 命名区分的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM