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. The function needs to ensure that if processing fails, the message is returned to the queue for reprocessing. Additionally, if a message repeatedly fails, it should be moved to a separate location for manual inspection. Which Service Bus message processing mode and related feature should the developer configure?

  1. APeekLock mode with manual completion and automatic dead-lettering.
  2. BReceiveAndDelete mode with automatic dead-lettering after retries.
  3. CPeekLock mode with manual completion and no dead-lettering.
  4. DReceiveAndDelete mode with no dead-lettering.
Show answer & explanation

Correct answer: A. PeekLock mode with manual completion and automatic dead-lettering.

PeekLock mode allows the function to 'lock' a message, process it, and then explicitly complete or abandon it. If processing fails and the message is abandoned (or the lock expires), it becomes available again. Service Bus automatically moves messages to a dead-letter queue after a configurable number of delivery attempts, addressing the requirement for failed messages to be inspected.

Why the other options are wrong

  • B. ReceiveAndDelete mode prevents reprocessing of failed messages, as they are deleted upon receipt.
  • C. No dead-lettering means repeatedly failing messages would not be moved for manual inspection, failing to meet a key requirement.
  • D. ReceiveAndDelete removes the message immediately, preventing reprocessing or dead-lettering.

Service Bus PeekLock

A message reception mode in Azure Service Bus where a message is locked for processing, preventing other consumers from seeing it. The consumer explicitly completes or abandons the message after processing.

  • Ensures 'at-least-once' delivery.
  • Allows messages to be returned to the queue on processing failure.
  • Works with dead-lettering for poison messages.

Memory trick: PeekLock is like taking a book from the library and returning it if you can't read it, eventually sending it to archives if too many try.

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