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?
- Call AcceptNextSessionAsync on a ServiceBusClient to obtain a ServiceBusSessionReceiver, keeping the default PeekLock receive mode.Cevap
- BCall AcceptNextSessionAsync on a ServiceBusClient to obtain a ServiceBusSessionReceiver and configure it to use ServiceBusReceiveMode.ReceiveAndDelete.
- CCreate a standard ServiceBusReceiver using CreateReceiver and configure it to filter by the vehicle's session ID using ServiceBusReceiverOptions.
- DCreate a standard ServiceBusReceiver and call PeekMessagesAsync to manually filter and order messages by session ID.
Cevap
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.
Adım Adım Çözüm
Anahtar Kavram
To process session-enabled Azure Service Bus queues reliably and in order, a session receiver must be used with the PeekLock receive mode.