In a previous article, we learnt all about Microservice Architecture in ASP.NET Core (I recommend reading this before continuing), API Gateways, Ocelot Configuration and much more. In this article, let’s talk about another aspect – Microservice Communication using RabbitMQ with ASP.NET Core. Essentially, we will learn how to enable communication between Microservices using RabbitMQ and MassTransit. Let’s get started!
Table of Contents
RabbitMQ is one of the most popular Message-Broker Service. It supports various messaging protocols. It basically gives your applications a common platform for sending and receiving messages. This ensures that your messages (data) is never lost and is successfully received by each intended consumer. RabbitMQ makes the entire process seemless.
In simple words, you will have a publisher that publishes messages to the message broker (RabbitMQ Server). Now the server stores the message in a queue. To this particular queue , multiple consumers can subscribe. Whenever there is a new message, each of the subscibers would receive it. An application can act as both producer / consumer based on how you configure it and what the requirement demands.
A message could consist of any kind of information like a simple string to a complex nested class. RabbitMQ stores these data within the server till a consumer connects and take the message off the queue for processing.
Additional, RabbitMQ provides a cool Dashboard for monitoring the messages and queues. We will be setting up this too later in this article!
There are quite a lot of advantages of using a queue based messaging solution rather that directly sending messages to the intendend consumer. Here are few of the advantages.
Here is a simple demonstration of work-flow in a basic RabbitMQ setup. Here consumer #3 is offline for a specific time. This does not in any way affect the integrity of the system. Even if all the consumers are offline, the messages are still in RabbitMQ waiting for the consumers to come online and take the message off their particular queues.
#asp.net core #microservices