You are developing a .NET background service using the Azure.Messaging.ServiceBus SDK to process payroll update messages from an Azure Service Bus queue named payroll-queue. The queue has sessions enabled.
The service must meet the following requirements:
- Process messages in the exact order they were sent within each session.
- Ensure that no message is lost if the background service encounters an unhandled exception during processing.
- Follow the principle of least privilege for security and access control.
Which two actions should you perform to implement these requirements? (Select two.)
- Call client.AcceptNextSessionAsync("payroll-queue") to obtain a session receiver.Answer
- Call receiver.CompleteMessageAsync(message) after the message is successfully processed.Answer
- CConfigure the receiver to use ServiceBusReceiveMode.ReceiveAndDelete to automatically delete messages upon retrieval.
- DAuthenticate the client using a Shared Access Signature (SAS) token that has the Manage permission on the Service Bus namespace.
- EConfigure the Azure Key Vault access policy to grant the service's identity only the Set permission to retrieve the Service Bus connection string.
Answer
To implement these requirements, you must obtain a session-enabled receiver using the AcceptNextSessionAsync method, and settle each message by calling CompleteMessageAsync after successful processing.
Accepting the next session ensures that messages with the same session ID are processed in sequence by a single receiver instance. Completing the message manually under PeekLock mode guarantees that if an unhandled exception occurs before completion, the lock will release and another instance can retry the message, ensuring zero message loss.
Step-by-Step Solution
Key Concept
Azure Service Bus sessions enable FIFO message ordering within a session context, which must be paired with PeekLock receive mode and explicit message settlement to ensure transactional reliability and prevent message loss.