In Azure function app I am using a service bus trigger to read messages.
[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. I am able to control this from host.josn
using below configurations.
{
"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. So I want to know if below options are possible,If yes how it can be achieved.
Default Syntax Format of Azure Functions Service Bus Trigger is like:
[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.
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.
If the Azure Function Stack belongs to .NET Core 3.1, then configure the AutoComplete
option manually in FunctionsStartup
file, the syntax is like:
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:
[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
Refer here , provides the information on ( AutoComplete
, AutoCompleteMessages
) naming differentiation based on Function Extension Version.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.