Soru

Zorluk: OrtaImplement Azure Service Bus Solutions

An e-prescribing platform processes medical prescriptions using an Azure Service Bus queue named `prescription-processing`. You are writing a C# console application that retrieves these prescriptions and updates a database. Because patient safety is critical, the application must guarantee that if a receiver crashes or encounters an unhandled exception while processing a prescription, the message is not lost and becomes available again for other receiver instances to process.

You write the following code segment to initialize the receiver and handle incoming messages:

csharp
string connectionString = "Endpoint=sb://...";
string queueName = "prescription-processing";
await using var client = new ServiceBusClient(connectionString);

var options = new ServiceBusReceiverOptions
{
// Line X
};
ServiceBusReceiver receiver = client.CreateReceiver(queueName, options);
ServiceBusReceivedMessage message = await receiver.ReceiveMessageAsync();

try
{
await ProcessPrescriptionAsync(message);
// Line Y
}
catch (Exception)
{
// Line Z
}

Which set of code segments should you use to complete the implementation?

  1. A
    Line X: ReceiveMode = ServiceBusReceiveMode.ReceiveAndDelete
    Line Y: // No action required
    Line Z: // No action required
  2. B
    Line X: ReceiveMode = ServiceBusReceiveMode.ReceiveAndDelete
    Line Y: await receiver.CompleteMessageAsync(message);
    Line Z: await receiver.AbandonMessageAsync(message);
  3. Line X: ReceiveMode = ServiceBusReceiveMode.PeekLock
    Line Y: await receiver.CompleteMessageAsync(message);
    Line Z: await receiver.AbandonMessageAsync(message);
    Cevap
  4. D
    Line X: ReceiveMode = ServiceBusReceiveMode.PeekLock
    Line Y: await receiver.AbandonMessageAsync(message);
    Line Z: await receiver.CompleteMessageAsync(message);

Cevap

Configure the receiver to use PeekLock mode, call CompleteMessageAsync in the try block, and call AbandonMessageAsync in the catch block.
The correct implementation configures the receiver to use PeekLock mode, which locks the message on the queue during processing. The message is explicitly completed with CompleteMessageAsync on success, and abandoned with AbandonMessageAsync on failure so it can be reprocessed.

Adım Adım Çözüm

1
Determine the correct Service Bus receive mode that prevents message loss during processing failures.
ServiceBusReceiveMode.PeekLock must be chosen for Line X, as ServiceBusReceiveMode.ReceiveAndDelete deletes the message immediately and cannot recover it on failure.
PeekLock keeps the message locked on the server and allows the application to explicitly complete or abandon the message.
2
Select the correct API call to settle the message upon successful processing in the try block.
receiver.CompleteMessageAsync(message) must be called for Line Y.
Completing the message informs Service Bus that the message was successfully processed and can be deleted from the queue.
3
Select the correct API call to release the message lock when an unhandled exception is caught in the catch block.
receiver.AbandonMessageAsync(message) must be called for Line Z.
Abandoning the message releases the lock immediately, allowing other receiver instances to retrieve and process the message without waiting for the lock duration to expire.

Anahtar Kavram

Message settlement and receive modes in Azure Service Bus
Tahmini Süre:1m 30s
Bu soruyu puanla