Question

Difficulty: EasyImplement Azure Service Bus Solutions

You are developing a C# console application to process customer support tickets from an Azure Service Bus queue named `support-tickets`. You need to retrieve a single message from the queue, process it, and remove it from the queue using the `Azure.Messaging.ServiceBus` SDK.

Arrange the steps in the correct order to implement this logic.

  1. 1Instantiate a `ServiceBusClient` using the connection string.
  2. 2Call the `CreateReceiver` method on the client instance to obtain a `ServiceBusReceiver` for the queue.
  3. 3Call the `ReceiveMessageAsync` method on the receiver instance to retrieve the message.
  4. 4Call the `CompleteMessageAsync` method on the receiver instance using the received message.

Answer

First, instantiate a ServiceBusClient. Second, call CreateReceiver on the client. Third, call ReceiveMessageAsync on the receiver. Finally, call CompleteMessageAsync on the receiver.
The correct sequence begins with establishing the connection via the ServiceBusClient. From there, a ServiceBusReceiver is created for the specific queue. You then retrieve the message using ReceiveMessageAsync, and after processing, settle the message by calling CompleteMessageAsync to remove it from the queue.

Step-by-Step Solution

1
Instantiate a ServiceBusClient using the namespace connection string.
A connection to the Service Bus namespace is initialized.
The client is the entry point for interacting with all Service Bus entities in the namespace.
2
Call client.CreateReceiver("support-tickets") to create a receiver.
A ServiceBusReceiver instance scoped to the 'support-tickets' queue is obtained.
Specific message operations like receiving and completing are performed by a receiver.
3
Call receiver.ReceiveMessageAsync().
A ServiceBusReceivedMessage is fetched from the queue.
The message payload must be retrieved into application memory to perform processing.
4
Call receiver.CompleteMessageAsync(message).
The message is settled and permanently removed from the Service Bus queue.
Completing the message informs Service Bus that processing succeeded and the lock should be released and the message deleted.

Key Concept

Message receiver lifecycle and message settlement in Azure Service Bus
Rate this question