IConfiguration vs IOptions NET
Synchronous and Asynchronous in .NET Core
Model Binding and Validation in ASP.NET Core
ControllerBase vs Controller in ASP.NET Core
ConfigureServices and Configure methods
IHostedService interface in .NET Core
ASP.NET Core request processing
| Eventual Consistency | Azure Service Bus in .NET Core | |
RabbitMQ in .NET Core |
RabbitMQ is an open-source message broker that implements the AMQP (Advanced Message Queuing Protocol). It enables asynchronous communication between services, decoupling producers (senders) and consumers (receivers).
Below is a simple example of publishing and consuming messages using RabbitMQ in a .NET Core application.
// Install-Package RabbitMQ.Client
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System;
using System.Text;
public class RabbitMQExample
{
public static void Main()
{
var factory = new ConnectionFactory() { HostName = "localhost" };
// Publisher
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: "demo-queue",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
string message = "Hello from .NET Core!";
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "",
routingKey: "demo-queue",
basicProperties: null,
body: body);
Console.WriteLine($" [x] Sent {message}");
}
// Consumer
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: "demo-queue",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body.ToArray();
var message = Encoding.UTF8.GetString(body);
Console.WriteLine($" [x] Received {message}");
};
channel.BasicConsume(queue: "demo-queue",
autoAck: true,
consumer: consumer);
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();
}
}
}
RabbitMQ is a powerful and flexible message broker that helps build scalable, decoupled, and resilient distributed systems in .NET Core. With proper design, monitoring, and security, it can handle high-throughput enterprise workloads effectively.
| Eventual Consistency | Azure Service Bus in .NET Core | |