Soru

Zorluk: ZorImplement Azure Service Bus Solutions

You are developing a C# console application that processes telemetry alerts from wind turbines using an Azure Service Bus queue. The application uses the `Azure.Messaging.ServiceBus` SDK.

You write the following code:

csharp
using System;
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;

// ... connection details omitted for brevity ...

var client = new ServiceBusClient(connectionString);
var options = new ServiceBusProcessorOptions
{
ReceiveMode = ServiceBusReceiveMode.PeekLock,
AutoCompleteMessages = false
};

ServiceBusProcessor processor = client.CreateProcessor(queueName, options);

processor.ProcessMessageAsync += async args =>
{
try
{
await ProcessAlertAsync(args.Message);
// Line X
}
catch (Exception)
{
// Line Y
}
};

You must ensure that:
1. Messages are not lost if the application crashes during processing.
2. Messages that fail due to transient errors are returned to the queue to be retried.
3. Successfully processed messages are removed from the queue immediately.

Which two code segments should you use to replace Line X and Line Y? (Select two.)

  1. At Line X: `await args.CompleteMessageAsync(args.Message);`Cevap
  2. At Line Y: `await args.AbandonMessageAsync(args.Message);`Cevap
  3. C
    At Line X: `await args.Message.CompleteAsync();`
  4. D
    At Line Y: `await args.DeadLetterMessageAsync(args.Message);`
  5. E
    At Line Y: `args.Message.Abandon();`

Cevap

To replace Line X and Line Y, you must call the asynchronous settlement methods `CompleteMessageAsync` and `AbandonMessageAsync` on the event arguments (`args`) object.
In PeekLock receive mode with manual settlement (`AutoCompleteMessages = false`), the processor does not automatically delete or release messages. Successful processing requires calling `CompleteMessageAsync` on the event arguments object to remove the message. Handling transient errors requires calling `AbandonMessageAsync` on the event arguments to return the message to the queue for future retry.

Adım Adım Çözüm

1
Determine the required receive and autocomplete configuration.
PeekLock mode is used, and AutoCompleteMessages is disabled, indicating manual settlement is required to prevent message loss on crashes.
By default or when AutoCompleteMessages is false, the developer is responsible for manually completing or abandoning the message.
2
Select the correct API call to settle successfully processed messages.
Call `await args.CompleteMessageAsync(args.Message);` at Line X.
Completing the message removes it from the queue and marks processing as successful.
3
Select the correct API call to handle transient processing errors.
Call `await args.AbandonMessageAsync(args.Message);` at Line Y.
Abandoning the message releases the lock, allowing the message to return to the queue for retry up to the maximum delivery count.

Anahtar Kavram

Manual message settlement in PeekLock mode using the Azure.Messaging.ServiceBus SDK
Bu soruyu puanla