chapter seven

7 Components for messaging and caching

 

This chapter covers

  • Understanding the fundamental concepts of message queues and message brokers
  • Integrating message brokers with Aspire
  • Using distributed caches and distributed locking for thread safety
  • Using Redis to implement both distributed locking and caching
  • Enabling the Redis management platform in Aspire

It’s common for distributed applications to have independent, self-contained services that communicate using message brokers. A message broker is a software system that mediates communication among applications, services, or microservices, enabling them to exchange information without being directly connected. It manages the sending, receiving, and routing of messages between systems. This is especially useful in distributed architectures, in which services often have to communicate asynchronously.

Typically, messaging queues provide this functionality. A service posts a message to a queue without knowing (or even caring) where it will end up. Another service subscribes to the queue, and this receiver service reads the messages from the queue in the order in which they arrive.

When such a service receives a message, it reads the message, extracts any data from it, and performs some actions. After the message is processed, it’s removed from the queue or marked as processed, depending on the specific message-broker implementation. Then the next message in the queue is processed, and so on.

7.1 Working with RabbitMQ

7.1.1 Hosting a RabbitMQ component

7.1.2 Adding order-processing functionality

7.1.3 Sending messages via RabbitMQ

7.1.4 Consuming RabbitMQ messages

7.2 Working with Azure Queue Storage

7.2.1 Hosting an emulated Azure Queue Storage component

7.2.2 Sending messages via Azure Queue Storage

7.2.3 Consuming Azure Queue Storage messages

7.3 Overview of distributed cache and lock

7.4 Setting up Redis for caching and locking

7.4.1 Installing a Redis component

7.4.2 Installing the Redis client for distributed caching

7.4.3 Using a distributed cache

7.4.4 Using a distributed lock

7.5 Managing the Redis cache

7.6 Summary