A worker microservice based on RabbitMQ
This section explains the modifications needed to use a message broker instead of gRPC communication with an internal queue. This kind of solution is usually more difficult to test and design but allows for better horizontal scaling, and also enables extra features at almost no cost since they are offered by the message broker itself.
We assume that RabbitMQ has already been installed and adequately prepared, as explained in the Installing RabbitMQ core subsection of Chapter 14, Implementing Microservices with .NET.
First, the ASP.NET Core project must be replaced by another Worker Service project. Also, this project must add the connection string to its configuration file and must call the AddStorage
extension method to add all the database services to the dependency injection engine. Below is the full content of the Program.cs
file:
using GrpcMicroService.HostedServices;
using GrpcMicroServiceStore;
IHost host = Host.CreateDefaultBuilder...