[ServiceBus] Adding AutoComplete option to host.json file
See original GitHub issueHi there,
I’m not really sure about where I should put this kind of request. Please, let me know if I’m in the wrong place.
We have moved some code dealing with ServiceBus messages to Azure Function. In our domain, when a message failed to be processed, we move it to the DeadLetter queue. Today, given the implementation of Microsoft.Azure.WebJobs.ServiceBus.MessageProcessor
supposed an Azure Function receiving the BrokeredMessage
, if we move the message to the DeadLetter queue, it calls the BrokeredMessage.CompleteAsync()
resulting in Exception and retries.
Here is a simple sample code to reproduce the issue:
public static class MyDequeuer
{
[FunctionName("SampleMessageExecutor")]
public static async Task Run(
[ServiceBusTrigger("test-queue", AccessRights.Listen, Connection = "ServiceBusConnectionString")]
BrokeredMessage brokeredMessage, ILogger log, ExecutionContext ctx)
{
await brokeredMessage.DeadLetterAsync();
}
}
If you look at the execution, you will get the following after the Function execution.
Exception thrown: 'System.ServiceModel.FaultException`1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.ServiceModel.FaultException`1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.ServiceModel.FaultException`1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.ServiceModel.FaultException`1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.ServiceModel.FaultException`1' in Microsoft.ServiceBus.dll
Exception thrown: 'Microsoft.ServiceBus.Messaging.MessageLockLostException' in Microsoft.ServiceBus.dll
Exception thrown: 'Microsoft.ServiceBus.Messaging.MessageLockLostException' in Microsoft.ServiceBus.dll
Exception thrown: 'Microsoft.ServiceBus.Messaging.MessageLockLostException' in Microsoft.ServiceBus.dll
Exception thrown: 'Microsoft.ServiceBus.Messaging.MessageLockLostException' in Microsoft.ServiceBus.dll
Exception thrown: 'Microsoft.ServiceBus.Messaging.MessageLockLostException' in Microsoft.ServiceBus.dll
Exception thrown: 'Microsoft.ServiceBus.Messaging.MessageLockLostException' in Microsoft.ServiceBus.dll
Is there any chance to add a way to customize the AutoComplete property from MessageOptions as we can do for AutoRenewTimeout
and MaxConcurrentCalls
from the host.json
file in an Azure Function context.
Thanks,
Issue Analytics
- State:
- Created 6 years ago
- Comments:25 (5 by maintainers)
@mathewc, basically what i want to do is manage the state myself and not rely on the function’s result. I am getting the same “The lock supplied is invalid” error that @kunalwadhwa is getting. That’s because for certain exceptions, I don’t want to retry it, but mark it as completed, while needing the function to fail so that I have a count of my failures in AppInsights.
The MessageProcessor code relies heavily on the function result. There is a chance to override that for result.Succeeded but we don’t check that failures.
Like @sescandell suggested, can’t we expose MessageOptions.AutoComplete through host.json and change to code to check that during failures too? That way, you leave the control to the user fully if they choose to do so using the MessageOptions.AutoComplete setting.
+1 for an option where the function can be responsible of the “message lifecycle”. Maybe the consumer wants to manually defer, or forgo abandoning and letting the message stay locked for 5 minutes before being retried. The way it’s currently implemented, I’ve seen Azure functions burn through numerous retries in seconds causing messages to dead letter immediately.