You are developing a .NET background worker service that processes batch database updates from an Azure Service Bus queue named `db-updates`. The queue has a message lock duration set to 1 minute.
Each update batch takes exactly 7 minutes to process. You write the following code to initialize the processor and handle messages:
csharp
var client = new ServiceBusClient(connectionString);
var options = new ServiceBusProcessorOptions
{
ReceiveMode = ServiceBusReceiveMode.PeekLock,
AutoCompleteMessages = false
};
var processor = client.CreateProcessor("db-updates", options);
processor.ProcessMessageAsync += MessageHandler;
processor.ProcessErrorAsync += ErrorHandler;
async Task MessageHandler(ProcessMessageEventArgs args)
{
await ProcessBatchAsync(args.Message); // Takes 7 minutes
await args.CompleteMessageAsync(args.Message);
}
The `MaxAutoLockRenewalDuration` property is left at its default configuration.
What is the behavior of the application when processing a message?
- AThe message is successfully completed at 7 minutes because the processor continues to renew the lock indefinitely as long as the MessageHandler task is actively running.
- The processor automatically renews the lock up to the default duration of 5 minutes. After 5 minutes, the lock expires and the message becomes visible to other receivers on the queue. When the handler finishes processing at 7 minutes and calls CompleteMessageAsync, a ServiceBusException is thrown.Cevap
- CThe lock expires after 1 minute, and the message is immediately moved to the dead-letter queue because the processor only performs automatic lock renewal when AutoCompleteMessages is set to true.
- DThe message lock expires after 1 minute, and the processor immediately terminates the MessageHandler task and throws a TimeoutException to the ErrorHandler.