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
| RabbitMQ vs Azure Service Bus | Publish/Subscribe Pattern | |
Kafka Basics |
Apache Kafka is a distributed event streaming platform designed for high-throughput, fault-tolerant, and real-time data pipelines. It is widely used for building event-driven architectures, data streaming, and real-time analytics.
Using the Confluent.Kafka NuGet package:
// Install-Package Confluent.Kafka
using Confluent.Kafka;
using System;
using System.Threading.Tasks;
public class KafkaExample
{
public static async Task Main()
{
var config = new ProducerConfig { BootstrapServers = "localhost:9092" };
// Producer
using (var producer = new ProducerBuilder<Null, string>(config).Build())
{
var dr = await producer.ProduceAsync("demo-topic", new Message<Null, string> { Value = "Hello Kafka!" });
Console.WriteLine($"Delivered '{dr.Value}' to '{dr.TopicPartitionOffset}'");
}
// Consumer
var consumerConfig = new ConsumerConfig
{
BootstrapServers = "localhost:9092",
GroupId = "demo-group",
AutoOffsetReset = AutoOffsetReset.Earliest
};
using (var consumer = new ConsumerBuilder<Ignore, string>(consumerConfig).Build())
{
consumer.Subscribe("demo-topic");
var cr = consumer.Consume();
Console.WriteLine($"Consumed message '{cr.Message.Value}' at: '{cr.TopicPartitionOffset}'.");
}
}
}
Apache Kafka is a powerful event streaming platform that enables real-time data pipelines and event-driven architectures. With proper design, monitoring, and security, it can handle enterprise-scale workloads efficiently.
| Aspect | Kafka | RabbitMQ | Azure Service Bus |
|---|---|---|---|
| Type | Distributed event streaming platform | Message broker (AMQP, MQTT, STOMP) | Fully managed enterprise messaging (Azure PaaS) |
| Use Cases | Real-time analytics, event sourcing, log aggregation | Microservices communication, IoT, work queues | Enterprise workflows, financial transactions, cloud-native apps |
| Message Model | Publish/subscribe with durable logs | Queues and exchanges (direct, fanout, topic) | Queues and topics with subscriptions |
| Scalability | Horizontal scaling with partitions | Clustering, but manual scaling | Automatic scaling built-in |
| Reliability | Data replicated across brokers | Requires HA setup and persistence | Geo-redundancy, dead-letter queues |
| Protocols | Kafka protocol (custom TCP) | AMQP, MQTT, STOMP, HTTP | AMQP 1.0 only |
| Hosting | Self-hosted or managed (Confluent Cloud, MSK) | Self-hosted (on-prem, Docker, Kubernetes) | Azure cloud only (fully managed) |
| Cost | Free (open-source), infra costs apply | Free (open-source), infra costs apply | Pay-as-you-go Azure pricing |
// Producer
var config = new ProducerConfig { BootstrapServers = "localhost:9092" };
using var producer = new ProducerBuilder<Null, string>(config).Build();
await producer.ProduceAsync("demo-topic", new Message<Null, string> { Value = "Hello Kafka!" });
var factory = new ConnectionFactory() { HostName = "localhost" };
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
channel.QueueDeclare("demo-queue", false, false, false, null);
channel.BasicPublish("", "demo-queue", null, Encoding.UTF8.GetBytes("Hello RabbitMQ!"));
await using var client = new ServiceBusClient("<connection-string>");
ServiceBusSender sender = client.CreateSender("demo-queue");
await sender.SendMessageAsync(new ServiceBusMessage("Hello Azure Service Bus!"));
Kafka is best for real-time streaming and analytics. RabbitMQ is ideal for microservices and IoT messaging. Azure Service Bus is perfect for enterprise-grade, cloud-native workflows. The right choice depends on whether you prioritize streaming performance, protocol flexibility, or managed reliability.
| RabbitMQ vs Azure Service Bus | Publish/Subscribe Pattern | |