Question

Difficulty: MediumImplement Azure Service Bus Solutions

You are developing a logistics tracking application that processes real-time location updates from delivery vehicles. To maintain the correct timeline of movements, updates for each vehicle must be processed in the exact chronological order they are received. You configure an Azure Service Bus queue with session support enabled.

You need to write the C# code using the Azure.Messaging.ServiceBus SDK to read these messages reliably. If a processing node fails, the message must not be lost.

Which approach should you use to instantiate and configure the receiver?

  1. Call AcceptNextSessionAsync on a ServiceBusClient to obtain a ServiceBusSessionReceiver, keeping the default PeekLock receive mode.Answer
  2. B
    Call AcceptNextSessionAsync on a ServiceBusClient to obtain a ServiceBusSessionReceiver and configure it to use ServiceBusReceiveMode.ReceiveAndDelete.
  3. C
    Create a standard ServiceBusReceiver using CreateReceiver and configure it to filter by the vehicle's session ID using ServiceBusReceiverOptions.
  4. D
    Create a standard ServiceBusReceiver and call PeekMessagesAsync to manually filter and order messages by session ID.

Answer

Call AcceptNextSessionAsync on a ServiceBusClient to obtain a ServiceBusSessionReceiver, keeping the default PeekLock receive mode.
The correct approach is to call AcceptNextSessionAsync to obtain a ServiceBusSessionReceiver while maintaining the default PeekLock receive mode. This ensures that session locks are respected for strict FIFO processing, and that messages are not lost if the processor crashes because the message is only completed after successful processing.

Step-by-Step Solution

1
Select the correct receiver class for session-enabled queues.
Identify that ServiceBusSessionReceiver must be used rather than ServiceBusReceiver.
Azure Service Bus requires session receivers to acquire a lock on a session and process messages within that session in FIFO order.
2
Determine the appropriate receive mode for reliability.
Select PeekLock mode instead of ReceiveAndDelete.
PeekLock ensures that the message remains on the queue locked by the receiver. If the receiver crashes, the lock expires and the message is made available again, preventing data loss.
3
Combine the session receiver initialization with the correct receive mode configuration.
Use AcceptNextSessionAsync with the default PeekLock receive mode.
This configuration satisfies both the session-based ordering and the message processing reliability requirements.

Key Concept

To process session-enabled Azure Service Bus queues reliably and in order, a session receiver must be used with the PeekLock receive mode.
Rate this question