Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.94k stars 441 forks source link

[ServiceBusTrigger] AutoComplete on a case-by-case basis? #6183

Open thomaslevesque opened 4 years ago

thomaslevesque commented 4 years ago

Is your question related to a specific version? If so, please specify:

Microsoft.NET.Sdk.Functions 3.0.7 Microsoft.Azure.WebJobs.Extensions.ServiceBus 4.1.1

What language does your question apply to? (e.g. C#, JavaScript, Java, All)

C#

Question

Is it possible to have AutoComplete enabled, but still take manual control over it in some functions?

In general, I'm fine with having AutoComplete to true, but I have some long-running functions that can run for longer than the lock duration, so I want to take explicit control of the message. Currently, I defer the message before I begin the actual work, and when I'm done, I retrieve the deferred message and complete it. This works, but I get an error after the message at the end of my function:

[08/06/2020 07:42:35] Executed 'MyFunction' (Succeeded, Id=fbd1d739-1b77-4ce3-99c7-cbae8cfae62b)
[08/06/2020 07:42:41] Message processing error (Action=Complete, ClientId=MessageReceiver3my-queue, EntityPath=my-queue, Endpoint=my-sb-namespace.servicebus.windows.net)
[08/06/2020 07:42:41] Microsoft.Azure.ServiceBus: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance.

I think this is because the function host tries to complete the message, which has already been completed.

Is it possible to disable AutoComplete for a specific function?

v-anvari commented 3 years ago

Hi @thomaslevesque , Have you tried adding the property in your main function code like below:

var options = new SessionHandlerOptions { AutoComplete = false, MessageWaitTimeout = TimeSpan.FromSeconds(3) };

Usually the property is added in host.json like below:

"SessionHandlerOptions": { "autoComplete": false }

But if my understanding is correct, you are looking for a solution for individual function. Please try adding it in your main function.cs and let us know if it works for you.

thomaslevesque commented 3 years ago

But if my understanding is correct, you are looking for a solution for individual function

I am.

Please try adding it in your main function.cs and let us know if it works for you.

I don't understand what you mean... I'm not using sessions.

v-anvari commented 3 years ago

Where exactly are you including AutoComplete in your code?

Usually added in Host.json, where AutoComplete uses anther setting. Are you talking about any other functionality, could you paste a link for reference.

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

thomaslevesque commented 3 years ago

On MessageHandlerOptions, not SessionHandlerOptions. But as mentioned in my original post, I don't want to disable AutoComplete globally.

v-anvari commented 3 years ago

Hi @thomaslevesque , In Host settings , we have the option of setting the Autocomplete only globally for now.

Tagging @alrod, for more inputs here. Is it possible to set the AutoComplete for a single function? Can we add this as a feature request?

mathewc commented 3 years ago

I think the ask here is the same as in https://github.com/Azure/azure-functions-servicebus-extension/issues/138? I.e., to make the existing host level MessageHandlerOptions configurable per function as well?

thomaslevesque commented 3 years ago

@mathewc yes, exactly

v-bbalaiagar commented 2 years ago

Hi @thomaslevesque, Let us know if the above information resolves your query, or if you have any further queries.

thomaslevesque commented 2 years ago

@v-bbalaiagar no, it doesn't.

ghost commented 2 years ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

thomaslevesque commented 2 years ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days

I did send feedback...

dhairya09 commented 2 years ago

Hi @v-bbalaiagar, @alrod, @v-anvari Quick question on the way to set this autocomplete: false for just one specific azure function and not affect all azure functions running on the function app ? Reason for asking is, what's specified here : https://github.com/Azure/azure-functions-servicebus-extension/issues/138 doesn't seem to work. Can you please share details on how this can be addressed ?

v-bbalaiagar commented 2 years ago

Tagging @mathewc , for more inputs