Now that we have defined the event bus abstraction, we can proceed by creating a new BackgroundService type that will use the IMediator interface to dispatch the sold-out messages. This book uses RabbitMQ because it is open source and easy to configure but keep in mind that there are tons of products and technologies related to this topic. Before continuing with the implementation of the background service, it is necessary to add some packages to the Cart.Infrastructure project:
dotnet add package RabbitMQ.Client
Furthermore, we can proceed by creating a new class that extends the BackgroundService type:
using System;using System.Threading;using System.Threading.Tasks;using Cart.Domain.Events;using Cart.Infrastructure.Configurations; ...