Exercise 4 – reading messages from a Service Bus queue using a .NET Core application
Previously, we sent some messages to a Service Bus queue. In this exercise, we will read them. To do that, we will add a new AzureQueueSample.Receiver
.NET Core console application. We will need to add the same NuGet packages as previously for the sender application: Azure.Messaging.ServiceBus
and NewtonSoft.Json
. We will also add AzureQueueSample.Domains
as a reference.
To read a message from the Service Bus queue, we use the following code:
public class Program { private const string ServiceBusConnectionString = "Endpoint =sb://appointmentqueue.servicebus.windows.net/;SharedAccessKey Name=RootManageSharedAccessKey;SharedAccessKey =1CqAJhjCv5M284qwRuLtApely83Ju9G48RxGuED2Zs0="; private const string QueueName = "myqueue"; static async Task Main(string[] args) { ...