Question

Difficulty: EasyImplement Azure Service Bus Solutions

A university course enrollment system uses an Azure Service Bus queue to process student registration requests. You are developing a C# console application that retrieves these requests. The application must guarantee that if the console application crashes during processing, the registration request is not lost and remains on the queue to be reprocessed by another instance. Which approach should you implement?

  1. Create a ServiceBusReceiver using ServiceBusReceiveMode.PeekLock and call CompleteMessageAsync after successfully processing the registration.Answer
  2. B
    Create a ServiceBusReceiver using ServiceBusReceiveMode.ReceiveAndDelete to process the registration requests.
  3. C
    Configure a Shared Access Signature (SAS) token on the Service Bus namespace with Manage, Send, and Listen permissions for the application client.
  4. D
    Grant the application's system-assigned managed identity Key Vault secret get permissions to retrieve the Service Bus connection string.

Answer

Create a ServiceBusReceiver using ServiceBusReceiveMode.PeekLock and call CompleteMessageAsync after successfully processing the registration.
Using the PeekLock receive mode ensures that the message is locked on the server side during processing but remains on the queue. If the application finishes processing successfully, it calls CompleteMessageAsync to delete the message. If the application crashes, the lock will expire, making the message available for other instances to process.

Step-by-Step Solution

1
Select the correct Service Bus receive mode that preserves the message in case of worker failure.
Using ServiceBusReceiveMode.PeekLock preserves the message on the server and locks it, preventing other workers from receiving it temporarily.
PeekLock ensures the message is not lost if the processing node fails.
2
Ensure the application explicitly signals completion of the message.
Invoke CompleteMessageAsync after processing is complete.
This removes the message from the queue after successful processing, ensuring it is not processed again.

Key Concept

Azure Service Bus receive modes (PeekLock vs ReceiveAndDelete)
Rate this question