liveBook · Manning

Chapter 7: Components for messaging and caching

What you will learn in chapter 7 of Building Distributed Applications that Work

Introduces how message brokers connect distributed services, how queued messages are processed, and how queue-based and topic-based delivery differ.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces how message brokers connect distributed services, how queued messages are processed, and how queue-based and topic-based delivery differ.

Key terms: message broker, asynchronously, message queue, subscribes, processed, Queue-based processing, Topic-based processing, subscriber

7.1 Working with RabbitMQ

Introduces RabbitMQ as an asynchronous message broker and explains why a background queue suits the book’s order-placement workflow.

Key terms: RabbitMQ, message broker, AMQP, asynchronous message delivery, order-tracking functionality, queue, asynchronously

7.1.1 Hosting a RabbitMQ component

This subsection identifies the package and host-file setup needed to add a RabbitMQ container to an Aspire application.

Key terms: Aspire.Hosting.RabbitMQ, Aspire host project, RabbitMQ container, AppHost.cs

7.1.2 Adding order-processing functionality

This section prepares the online shop to place orders by identifying products, representing and storing orders, and adding a minimal ordering UI.

Key terms: ProductsApiClient, product ID, quantity, ProductDto, /products endpoint, Orders, OrderItems, Models, database-creation script, Home.razor

7.1.3 Sending messages via RabbitMQ

This section adds an order-placement endpoint that saves an order and publishes its ID through RabbitMQ.

Key terms: Aspire.RabbitMQ.Client, OnlineShop.ApiService, Program.cs, RabbitMQ component, POST endpoint, basket, order amount, order items, transaction, rollback

7.1.4 Consuming RabbitMQ messages

This section explains how a RabbitMQ message starts order tracking and how later location updates reach the tracking system.

Key terms: LocationUpdater, orders.created, initial order-tracking location, LocationHub, SignalR client, UpdateLocation

7.2 Working with Azure Queue Storage

Introduces Azure Queue Storage as a simple messaging alternative and shows how it fits the existing order-placement and location-tracking workflow.

Key terms: Azure Queue Storage, Azure Storage account, asynchronous communication, order-placement endpoint, location-tracking background service, queue

7.2.1 Hosting an emulated Azure Queue Storage component

This subsection identifies the package needed to host Azure Queue Storage and the services that receive its reference.

Key terms: Azure Queue Storage, Azure Storage component, Aspire.Hosting.Azure.Storage, AppHost.cs

7.2.2 Sending messages via Azure Queue Storage

This section shows how to register an Azure Queue Storage client and use it to publish an order-placement message.

Key terms: Aspire.Azure.Storage.Queues, QueueServiceClient, Queue Storage reference, queue client, orders-created, Azure Queue Storage

7.2.3 Consuming Azure Queue Storage messages

Explains how the LocationUpdater service consumes Azure Queue Storage messages and why background message processing matters in distributed applications.

Key terms: LocationUpdater, ExecuteAsync(), cancellation, batch of 10 messages, for-each block, message brokers, message queues, synchronously, background

7.3 Overview of distributed cache and lock

This section explains how a shared cache improves access to frequently used data and how distributed locks coordinate access to shared resources.

Key terms: distributed caching, RAM, Redis, distributed locking, distributed lock, race conditions, distributed cache

7.4 Setting up Redis for caching and locking

Introduces the upcoming Redis setup for caching and locking in an Aspire-hosted application.

7.4.1 Installing a Redis component

This subsection shows how to add a Redis component to an Aspire host, pass it to the API service, and optionally add Redis Commander.

Key terms: Aspire.Hosting.Redis, Aspire host application, Redis component, API service, AppHost.cs, WithRedisCommander(), Redis Commander, Aspire dashboard

7.4.2 Installing the Redis client for distributed caching

This subsection sets up the API application to connect to an Aspire-hosted Redis resource for distributed caching.

Key terms: OnlineShop.ApiService, Aspire.StackExchange.Redis.DistributedCaching, Program.cs, connectionName, cache

7.4.3 Using a distributed cache

Shows how the products endpoint caches database results in Redis, shares cached data across API instances, and invalidates entries when products change.

Key terms: IDistributedCache, GetStringAsync(), SetStringAsync(), JSON string, distributed cache, scale out, service instance, invalidate, RemoveAsync(), repopulated

7.4.4 Using a distributed lock

This section shows how a simplified order-placement endpoint uses a Redis lock to protect stock updates when orders overlap.

Key terms: distributed locking, thread-safe, stock, IConnectionMultiplexer, GetDatabase(), LockTakeAsync(), lock key, lock value, lock expiry time, LockReleaseAsync()

7.5 Managing the Redis cache

This section shows how to inspect and manage Redis data with Redis Commander and explains how an Aspire AppHost can reference externally hosted Redis through a connection string.

Key terms: Redis Commander, Aspire dashboard, cached data, locks, generic connection string, builder.AddConnectionString(), AppHost

7.6 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 6: Integration testing and monitoring Chapter 8: Application security in Aspire →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.