A corporate financial system uses an Azure Service Bus queue named `expense-claims` to process employee reimbursement requests. You are writing the message consumption logic in C# using the `Azure.Messaging.ServiceBus` SDK. To ensure reliability, if the consumer application fails mid-operation, the message must remain in the queue and be re-delivered after the lock duration expires. Once the expense claim is successfully recorded, the message must be deleted.
Which two actions should you take to implement this workflow? (Select two)
- Set the receive mode in the ServiceBusReceiverOptions to ServiceBusReceiveMode.PeekLock.Answer
- BSet the receive mode in the ServiceBusReceiverOptions to ServiceBusReceiveMode.ReceiveAndDelete.
- Invoke the CompleteMessageAsync method on the receiver object when processing completes successfully.Answer
- DInvoke the AbandonMessageAsync method on the receiver object when processing completes successfully.
Answer
To ensure reliable message processing, you must configure the ServiceBusReceiverOptions to use ServiceBusReceiveMode.PeekLock and invoke the CompleteMessageAsync method on the receiver object when processing completes successfully.
To ensure message durability and avoid data loss on application crashes, the receiver must be set to use PeekLock. This mode locks the message for the consumer while keeping it in the queue. Upon successful processing, the application must explicitly call CompleteMessageAsync to delete the message.
Step-by-Step Solution
Key Concept
Reliable message processing using PeekLock and CompleteMessageAsync