Question

Difficulty: EasyImplement Azure Service Bus Solutions

A healthcare provider uses an Azure Service Bus queue named `patient-checkins` to manage incoming patient arrival data. You are writing a C# client using the Azure.Messaging.ServiceBus SDK to retrieve and process these messages. You must ensure that messages are only removed from the queue after they have been successfully processed, preventing message loss if the client application crashes during execution. Which configuration or approach should you implement?

  1. Initialize the `ServiceBusReceiver` with `ServiceBusReceiveMode.PeekLock` and call `CompleteMessageAsync` after the message is successfully processed.Answer
  2. B
    Initialize the `ServiceBusReceiver` with `ServiceBusReceiveMode.ReceiveAndDelete` to automatically handle message removal upon retrieval.
  3. C
    Grant the client application's system-assigned managed identity a Key Vault Access Policy with secret retrieval permissions, without assigning any Azure Service Bus RBAC roles.
  4. D
    Connect to the queue using a Shared Access Signature (SAS) token configured with namespace-level Manage claims.

Answer

Initialize the `ServiceBusReceiver` with `ServiceBusReceiveMode.PeekLock` and call `CompleteMessageAsync` after the message is successfully processed.
The correct answer is to use `ServiceBusReceiveMode.PeekLock` and call `CompleteMessageAsync` after processing. In PeekLock mode, the receiver locks the message on the queue for a specified duration, allowing the receiver to complete the message once successfully processed. If the receiver crashes, the lock expires, and the message becomes available to other receivers again, preventing loss.

Step-by-Step Solution

1
Determine the required message reliability level.
At-least-once delivery is required to prevent message loss.
The system must recover messages if the client crashes mid-execution.
2
Select the appropriate Service Bus receive mode.
`ServiceBusReceiveMode.PeekLock` is selected.
PeekLock locks the message on the queue during processing, allowing it to reappear if the lock duration expires without settlement.
3
Implement message settlement in code.
Call `CompleteMessageAsync` once the processing succeeds.
This explicitly completes the transaction on the Service Bus server, removing the message from the queue.

Key Concept

Azure Service Bus Receive Modes and Message Settlement
Rate this question