liveBook · Manning

Azure Storage Queues

As explained in Building Distributed Applications that Work

An Azure service that stores messages in queues for asynchronous exchange between services.

Azure Queue Storage is a queue service within an Azure Storage account. It enables asynchronous communication between applications and services, offering straightforward message handling for basic task management. section 7.2

In an online shop, the order-placement endpoint publishes an order-created message; a location-tracking background service consumes it and updates delivery information. This lets the update run in the background rather than delaying the user-facing request. section 7.2 section 7.2.3

A typical Aspire setup connects the applications to a queue through these steps:

  • Add an emulated Azure Storage component and its queue in the Aspire host, then reference the queue from the API and frontend projects. section 7.2.1
  • Register the queue client in the API, create the `orders-created` queue if needed, and send a serialized order message. section 7.2.2
  • Use a background service to receive up to ten messages per iteration and process each order. section 7.2.3
var storage = builder.AddAzureStorage("storage")
   .RunAsEmulator();


var queues = storage.AddQueues("queues");

builder
   .AddProject<Projects.OnlineShop_ApiService>(
       "apiservice")
   .WaitFor(queues)
   .WithReference(queues)...

Aspire host configuration for running Azure Storage with an emulator and adding a queue. section 7.2.1

var queueClient = queueServiceClient
    .GetQueueClient("orders-created");
await queueClient.CreateIfNotExistsAsync();

while (!stoppingToken.IsCancellationRequested)
{

    QueueMessage[] messages = queueClient
    .ReceiveMessages(maxMessages: 10);

    foreach (var message in messages)
    {
        var body =
            JsonSerializer.Deserialize<OrderCreatedMessage>(message.MessageText);

        await SetInitialDeliveryLocation(
                body.OrderId,
                stoppingToken);
    }
}

A background-service example that creates the queue, receives message batches, and processes order IDs. section 7.2.3

How Building Distributed Applications that Work covers it

How deep it goes
Shows Aspire host setup, message publication, and batch consumption without detailing message-failure handling.
Examples
Uses an online shop where an order endpoint publishes a message and a location updater processes it.
What you can do after
Apply Azure Queue Storage through .NET Aspire to publish order messages and consume them in a background service.
How it connects
Connects Azure Storage accounts with asynchronous messaging, Aspire, background services, and order processing.

Also explained in

Compare how 2 books explain Azure Storage Queues →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Distributed Applications that Work. The section links point to the parts of the book it draws on.