In this article, we will discuss the RabbitMQ Message Queue and its implementation using .NET Core 6 API as a Message Producer and Console Application as a Message Consumer.
Agenda
- Introduction of RabbitMQ
- Benefits of using RabbitMQ
- Implementation of RabbitMQ in .NET Core 6
Prerequisites
- Visual Studio 2022
- Docker Desktop
- .NET Core 6 SDK
Introduction of RabbitMQ
- Rabbit MQ is the message broker that acts as a middleware while using multiple microservices.
- RabbitMQ is an open-source message broker software. It is sometimes also called message-oriented middleware.
- RabbitMQ is written in the Erlang programming language.
- RabbitMQ is used to reduce the load and delivery time of a web application when some of the resources have taken a lot of time to process the data.

- As you can see in the diagram above, there is one producer who sends a message to the RabbitMQ server. The server will store that message inside the queue in a FIFO manner.
- Once the producer has sent the message to the queue, there may be multiple consumers who want the message produced by the producer. In that case, consumers subscribe to the message and get that message from the Message Queue, as you see in the above diagram.
- In this section, we will use one eCommerce Site as an example to understand more fully.
- There are multiple microservices running in the background while we are using the eCommerce website. There is one service that takes care of order details and another service that takes care of payment details and receipts.
- Suppose we placed one order. At that time, the order service will start and process our order. After taking the order details, it will send data to the payment service, which takes the payment and sends the payment receipt to the end-users.
- In this case, there may be a chance of some technical issue occurring in the payment service. If the user did not receive the payment receipt due to this, the user would be impacted and connected with the support team ti try to learn the status of the order.
- There may be another scenario on the user(consumer) side. Perhaps due to some technical issue, the user is exited from the application when the payment is in process. However, he will not get any receipt details after payment is successfully processed from backend services.
- In these scenarios, RabbitMQ plays an essential role in processing messages in the message queue. So, when the consumer gets online, he will receive that order receipt message from the message queue, produced by the producer, without impacting the web application.
- All these examples are just for understanding purposes. There are a lot of scenarios in which RabbitMQ may play an important role while using multiple microservices. Sometimes RabbitMQ is used fully to load balancing between multiple services or for many other purposes.
Benefits of using RabbitMQ
There are many benefits to using a Message Broker to send data to the consumer. Below, we will discuss a few of these benefits.
High Availability
When multiple microservices are used by the application, if one of the microservices is stopped due to technical reasons at that time, the message will never be lost. Instead, it persists in the RabbitMQ server. After some time, when our service starts working, it will connect with RabbitMQ and take the pending message easily.
Scalability
When we use RabbitMQ, at that time, our application does not depend on only one server and virtual machine to process a request. If our server is stopped at that time, RabbitMQ will transfer our application load to another server that has the same services running in the background.
RabbitMQ Implementation with .NET Core 6
Let’s start with the practical implementation of RabbitMQ using .NET Core 6 Web API as a producer and Console Application as a consumer.
Step 1. Create a .NET Core API project.

Step 2. Configure your project.

Step 3. Provide additional information about your project.

Step 4. Project Structure of Producer Application.

Step 5. Install a few NuGet packages.

Step 6. Create a Product Class inside the Models folder.
namespace RabitMqProductAPI.Models {
public class Product {
public int ProductId {
get;
set;
}
public string ProductName {
get;
set;
}
public string ProductDescription {
get;
set;
}
public int ProductPrice {
get;
set;
}
public int ProductStock {
get;
set;
}
}
}
Step 7. Next, create a DbContextClass.cs class inside the Data folder.
using Microsoft.EntityFrameworkCore;
using RabitMqProductAPI.Models;
namespace RabitMqProductAPI.Data {
public class DbContextClass: DbContext {
protected readonly IConfiguration Configuration;
public DbContextClass(IConfiguration configuration) {
Configuration = configuration;
}
protected override void OnConfiguring(DbContextOptionsBuilder options) {
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
}
public DbSet < Product > Products {
get;
set;
}
}
}
Step 8. Later on, create an IProductService.cs and ProductService.cs class inside the Services folder.
using RabitMqProductAPI.Models;
namespace RabitMqProductAPI.Services {
public interface IProductService {
public IEnumerable < Product > GetProductList();
public Product GetProductById(int id);
public Product AddProduct(Product product);
public Product UpdateProduct(Product product);
public bool DeleteProduct(int Id);
}
}
Create a ProductService.cs.
using RabitMqProductAPI.Data;
using RabitMqProductAPI.Models;
namespace RabitMqProductAPI.Services {
public class ProductService: IProductService {
private readonly DbContextClass _dbContext;
public ProductService(DbContextClass dbContext) {
_dbContext = dbContext;
}
public IEnumerable < Product > GetProductList() {
return _dbContext.Products.ToList();
}
public Product GetProductById(int id) {
return _dbContext.Products.Where(x => x.ProductId == id).FirstOrDefault();
}
public Product AddProduct(Product product) {
var result = _dbContext.Products.Add(product);
_dbContext.SaveChanges();
return result.Entity;
}
public Product UpdateProduct(Product product) {
var result = _dbContext.Products.Update(product);
_dbContext.SaveChanges();
return result.Entity;
}
public bool DeleteProduct(int Id) {
var filteredData = _dbContext.Products.Where(x => x.ProductId == Id).FirstOrDefault();
var result = _dbContext.Remove(filteredData);
_dbContext.SaveChanges();
return result != null ? true : false;
}
}
}
Step 9. Create IRabitMQProducer.cs and RabitMQProducer.cs classes for the message queue inside the RabbitMQ folder.













Manvendra PatelPosted Sep 3, 2025, 1:38 AM
Awesome article, thank you so much! You can also include the type of queue
Anandu G NathPosted Sep 6, 2024, 5:08 AM
Good article
GauravPosted Dec 26, 2023, 4:15 PM
Thanks for this article. How will deploy this console application? For demo purposes you have shown both web api and console applications running which is fine but do we need to keep this console application always running when deploying to our server? Waht if I need 10 such queues so does it mean I need to create 10 console applications. Please clarify.
Pranay BogaPosted Sep 13, 2023, 2:19 PM
How can we insert data into queues when data is inserted in database through database trigger or sp's and when data is inserted in queue we need to send that to .net side and from there through signalR to client app. How can we achieve that ?
Aveeral SinhaPosted Nov 13, 2022, 5:10 AM
Hi Jaydeep, thanks for the wonderful explanation! I am looking for the consumer to be an ASP.NET core application. Do you have any example for that as well?
Erick MouraPosted Oct 7, 2022, 10:33 PM
Thanks for the very useful article!
Yogesh SPosted Sep 7, 2022, 5:07 PM
Can you explain the step 14 please . I can't understand that..!
Yogesh SPosted Sep 7, 2022, 12:49 PM
Nice article . Thank you for sharing this..
PRASANNA MSPosted Sep 6, 2022, 12:14 PM
Wonderful Article.. thanks for sharing...