Implementing the Publish-Subscribe pattern
The Publish-Subscribe pattern (Pub-Sub) is very similar to what we did using MediatR and what we explored in the Getting started with message queues section. However, instead of sending one message to one handler (or enqueuing a message), we publish (send) a message (or event) to zero or more subscribers (handlers). Moreover, the publisher is not aware of the subscribers; it only sends messages out, hoping for the best (also known as fire and forget).
We can use publish-subscribe in-process or in a distributed system through a message broker. The message broker is responsible for delivering the messages to the subscribers. That is the way to go for microservices and other types of distributed systems since they are not running in a single process.
This pattern has many advantages over other ways of communication. For example, we could recreate the state of a database by replaying the events (messages) that happened in the system, leading...