Microsoft Certified: Azure Developer Associate (AZ-204)Connect to and consume Azure services and third-party servicesMedium

A developer is creating an Azure Function that processes incoming messages from an Azure Service Bus Queue. To ensure that messages are not lost if the function encounters an error during processing, and can be retried later, the function needs to explicitly acknowledge successful processing. If the processing fails, the message should eventually be returned to the queue or moved to a dead-letter queue. Which message receiving mode should the Azure Function use?

  1. APeekLock
  2. BSession-enabled Receive
  3. CReceiveAndDelete
  4. DBatch Receive
Show answer & explanation

Correct answer: A. PeekLock

PeekLock mode ensures that a message is not automatically deleted from the queue upon retrieval. The function receives a lock on the message and must explicitly complete it after successful processing. If the function fails or the lock expires, the message becomes available again (or moves to the dead-letter queue after multiple retries), guaranteeing at-least-once delivery and preventing message loss.

Why the other options are wrong

  • B. Session-enabled Receive is for ordered processing of related messages within a session, not directly for handling individual message failures and retries.
  • C. ReceiveAndDelete mode immediately deletes the message from the queue upon retrieval, leading to potential data loss if processing fails.
  • D. Batch Receive allows receiving multiple messages at once but doesn't define the message disposition behavior (delete vs. lock) itself.

Service Bus PeekLock Mode

A message receiving mode in Azure Service Bus that provides explicit control over message completion or abandonment.

  • Message is locked upon retrieval, not deleted.
  • Requires explicit completion to remove from queue.
  • Ensures messages are not lost if consumer fails.

Memory trick: PeekLock: See the message, take a lock, then decide its fate.

More Connect to and consume Azure services and third-party services questions