You are developing a .NET background worker service that processes critical payment transactions from an Azure Service Bus queue. The processing of each payment involves calling a third-party gateway, which can take up to 2 minutes during peak hours. The Service Bus queue is configured with a default LockDuration of 30 seconds and a MaxDeliveryCount of 5.
You must ensure that:
1. Messages are never lost if the worker service crashes or restarts mid-transaction.
2. Messages are not processed by multiple workers simultaneously if processing exceeds 30 seconds.
3. Message processing failures due to transient errors are immediately released back to the queue for retry up to the maximum delivery count.
You use the Azure.Messaging.ServiceBus SDK to initialize the processor with the following code:
csharp
var client = new ServiceBusClient(connectionString);
var options = new ServiceBusProcessorOptions
{
ReceiveMode = [ReceiveMode],
AutoCompleteMessages = [AutoComplete],
MaxAutoLockRenewalDuration = [MaxAutoLockRenewal]
};
ServiceBusProcessor processor = client.CreateProcessor(queueName, options);
processor.ProcessMessageAsync += async args =>
{
try
{
await ProcessPaymentWithRetryAsync(args.Message);
[CompleteMessage]
}
catch (Exception)
{
[HandleException]
}
};
Which set of configuration values and code segments should you use to meet these requirements?
- [ReceiveMode] = ServiceBusReceiveMode.PeekLock
[AutoComplete] = false
[MaxAutoLockRenewal] = TimeSpan.FromMinutes(5)
[CompleteMessage] = await args.CompleteMessageAsync(args.Message);
[HandleException] = await args.AbandonMessageAsync(args.Message);Answer - B[ReceiveMode] = ServiceBusReceiveMode.ReceiveAndDelete
[AutoComplete] = true
[MaxAutoLockRenewal] = TimeSpan.FromMinutes(5)
[CompleteMessage] = // No-op
[HandleException] = // No-op - C[ReceiveMode] = ServiceBusReceiveMode.PeekLock
[AutoComplete] = false
[MaxAutoLockRenewal] = TimeSpan.Zero
[CompleteMessage] = await args.CompleteMessageAsync(args.Message);
[HandleException] = await args.AbandonMessageAsync(args.Message); - D[ReceiveMode] = ServiceBusReceiveMode.PeekLock
[AutoComplete] = true
[MaxAutoLockRenewal] = TimeSpan.FromMinutes(5)
[CompleteMessage] = await args.CompleteMessageAsync(args.Message);
[HandleException] = await args.AbandonMessageAsync(args.Message);