RabbitMQ in .NET Core

21 April 2021 at 10:00 by ParTech Media - Post a comment

A typical piece of software usually requires messaging to connect and scale itself. Such applications either connect to each other or to a device or to the data of users with the help of messaging. This makes them look as if they are the components of one large application. Messaging is an asynchronous task which decouples the applications by separating the task of receiving and sending messages.

RabbitMQ is a message broker which provides the applications a common platform to send and receive messages and keeps the messages safe until they are received. So, let us quickly understand what is RabbitMQ in .NET Core and how it is useful.

Table of contents

  • What is RabbitMQ?
  • Features of RabbitMQ
  • How RabbitMQ works?
  • Benefits of using RabbitMQ in .NET Core
  • Conclusion

What is RabbitMQ?

RabbitMQ in .NET Core is an open-source and extensible message queuing solution which is completely free to use for anyone. RabbitMQ is used with Message Queuing Telemetry Transport (MQTT) which is one of the popular messaging solutions. It is also a message broker which also understands Advanced Message Queuing Protocol (AMQP).

RabbitMQ is scalable, available, and also fault-tolerant. RabbitMQ is implemented in Erlang OTP, which is a technology that is usually used for making a solution highly scalable, and fault-tolerant. The built solutions are so capable that they are able to handle concurrent operations carried out in large numbers, which is the case with RabbitMQ and other systems such as MongooseIM, WhatsApp, etc.

It provides multiple Quality of Service (QoS) required while developing an application so that the user doesn't have to worry about the loss of the message. RabbitMQ can also be considered a middleware layer that provides several services in the application that you are building to facilitate your communication with other people. It also provides extensive decoupling of applications which is enabled by the usage of an efficient message and finely-grained routing.

The protocols supported by the RabbitMQ are:-

  • AMQP 0-9-1
  • MQTT
  • AMQP 1.0
  • HTTP and WebSocket

Important Terms in RabbitMQ

Before we see how RabbitMQ works, we need to know some key terms that will help in understanding its working better.

  • Message:- Messages can contain any type of information from a simple text message to serialized objects.
  • Channel:- It is a communication line that is logical in nature and links the publisher with the listener.
  • Queue:- The RabbitMQ queue follows the first in first out algorithm for storing the messages from the publishers.
  • Connection:- The connection of RabbitMQ is based on the protocols and is a necessity for having channels. It connects the server to the client.
  • Consumer:- The client that is connected to the channel listening to the queues to read the messages published on it.
  • Publisher:- The client that is connected to the queue where it publishes the messages.
  • Notification:- The service health is monitored and is customized to alert based on the different metrics.
  • Dead Letter:- In RabbitMQ, the messages that were not read by the listeners are stored in the dead letters.
  • Route:- The RabbitMQ routes send the messages to the correct queues on the basis of their exchanges and their routing keys.
  • Exchange:- Exchange is nothing but an algorithm that decides as to in which queue the message will be stored.
  • Bindings:- It is the link between the queue and an exchange.

How RabbitMQ works?

There are multiple useful exchange types which are offered by RabbitMQ. These exchange types cover most of the use-cases of messaging. Exchange is nothing but an algorithm that decides the queue in which the message will be stored. Now, each consumer receives the queue on the basis of logic. There are four types of logics that can be used in Exchange -

  1. Direct Exchange: This exchange matches the routing key of the incoming message with the binding key of the queue. It then delivers the incoming message to the queue whose binding key exactly matches. It can be thought of as a one-to-one message delivery system as it uses routing keys as a queue name to bind the queue. By using the binding keys for multiple uses it becomes simple to deliver the message to multiple queues.
  2. Topic Exchange: This exchange matches the routing key of the incoming message with the wild-card binding key of the queue and delivers the incoming message to the queue whose wild-card binding key exactly matches. For a compound routing key, there can be wild-card matching criteria for binding keys. For example, logs.UIi.error and logs.accounting.error will be the matched routing keys for the binding key logs.*.error. It helps the programmer to write simple services by the usage of this exchange, where well-contained logic is present and the message arrives at the correct services through the usage of RabbitMQ.
  3. Fanout Exchange: There are certain messages which are to be delivered to all the queues. In such cases, fanout exchange can be used instead of writing huge chunks of multicast logical codes in the application we are building. Without any need of specifying the binding key, each service is bound with the appropriate queue to the exchange. All this happens automatically with the usage of RabbitMQ Fanout Exchange. Even if a binding key is specified while coding, it is just ignored by the fanout exchange and the broadcast or route messages are delivered to all the queues bound to it.
  4. Headers Exchange: The structure of Advanced Message Queuing Protocol (AMQP) is enhanced by headers exchange. The complicated routings based on the headers of the Advanced Message Queuing Protocol (AMQP) message are also carried out by this exchange. The metadata attached to each message sent by AMQP is called a header.

Benefits of using RabbitMq in .NET Core

  • In languages such as JSON, it provides multi-platform communication.
  • It provides async operations thereby not keeping the services waiting.
  • Its features are improved regularly as it is open source with a large community working on it.
  • A wide range of languages is accepted.
  • Various types of protocols are used to exchange messages.


From the above article, we can see that almost all communications can be done through RabbitMQ. RabbitMQ is becoming one of the most in-demand technologies used for communication between applications and the user’s devices. The best part is - Being an open-source technology, it can be used by anyone anytime without spending a dime on it.