Question

Difficulty: MediumImplement Azure Service Bus Solutions

A food delivery platform dispatch system uses Azure Service Bus to process orders for multiple restaurants. The system must guarantee that orders for each restaurant are processed in the exact order they are received. Additionally, if the consumer application crashes during processing, the message must not be lost and should eventually be moved to the dead-letter queue after a specific number of retries. Which two configuration or implementation steps should you perform to meet these requirements? (Select two.)

  1. Enable sessions on the queue and set the SessionId property on each ServiceBusMessage to the restaurant's unique identifier.Answer
  2. Use the ServiceBusSessionProcessor to read messages and call CompleteMessageAsync on the receiver after successful processing of a message.Answer
  3. C
    Configure the receiver to use ReceiveAndDelete mode to ensure that messages that fail processing are automatically routed to the dead-letter queue.
  4. D
    Create a Shared Access Signature (SAS) token with Manage permissions at the namespace level to authenticate the consumer application.

Answer

Enable sessions on the queue and set the SessionId property on each ServiceBusMessage to the restaurant's unique identifier, and use the ServiceBusSessionProcessor to read messages and call CompleteMessageAsync after successful processing.
To achieve FIFO ordering per restaurant, you must enable sessions on the queue and assign the SessionId property on outgoing messages to the restaurant's identifier. To prevent message loss in case of processing crashes, you must use PeekLock mode (implicitly used by ServiceBusSessionProcessor when calling CompleteMessageAsync explicitly after processing) so that incomplete messages are returned to the queue and eventually dead-lettered after the maximum delivery count is reached.

Step-by-Step Solution

1
Ensure ordered delivery by grouping messages.
Sessions are enabled on the queue, and each message is stamped with a SessionId corresponding to the restaurant ID, enabling FIFO delivery per restaurant.
Azure Service Bus queues do not guarantee FIFO ordering across all messages unless sessions are used to group related messages.
2
Select the correct message processing client.
ServiceBusSessionProcessor is selected for consuming session-locked messages.
Standard non-session processors cannot process session-enabled queues.
3
Configure the correct receive mode to prevent loss.
PeekLock mode (default) is used, and CompleteMessageAsync is called only after successful processing.
If processing fails or the receiver crashes, the lock will expire, making the message available for retry, and eventually moving to the dead-letter queue after max delivery attempts are exceeded.

Key Concept

Azure Service Bus Sessions and Message Lock Modes
Rate this question