This project demonstrates a basic implementation of Apache Kafka using C# .NET 6.0, featuring both producer and consumer applications.
The solution consists of two main components:
- KafkaProducerApplication: A console application that produces messages to Kafka topics
- KafkaConsumerApplication: A console application that consumes messages from Kafka topics
- .NET 6.0 SDK
- Apache Kafka running locally (default port: 9092)
- Confluent.Kafka NuGet package (version 2.2.0)
- Simple console-based message producer
- Configurable message input
- Sends messages to a specified Kafka topic
- Uses localhost:9092 as the default bootstrap server
- Multiple consumer implementations:
- Consumer1: Background service consumer
- Consumer2: Background service consumer
- KafkaConsumer: Basic consumer implementation
- Supports message consumption from specified topics
- Implements consumer group functionality
- Auto offset reset configuration
- Background service implementation for continuous message processing
var config = new ProducerConfig
{
BootstrapServers = "localhost:9092",
BrokerAddressFamily = BrokerAddressFamily.V4
};var config = new ConsumerConfig
{
BootstrapServers = "localhost:9092",
GroupId = "new-consumer-group",
AutoOffsetReset = AutoOffsetReset.Earliest
};- Clone the repository
- Ensure Kafka is running on localhost:9092
- Build the solution:
dotnet build
- Run the producer application:
cd KafkaProducerApplication dotnet run - Run the consumer application:
cd KafkaConsumerApplication dotnet run
- Confluent.Kafka (2.2.0)
- Microsoft.Extensions.Hosting (7.0.1)
- Microsoft.Extensions.Hosting.Abstractions (7.0.0)
The solution follows a modular architecture with separate projects for producer and consumer applications. The consumer application implements multiple consumer types to demonstrate different approaches to message consumption:
- Background Service Consumers (Consumer1, Consumer2)
- Basic Kafka Consumer
- Kafka Consumer Service
- The default topic used in the implementation is "myTopic"
- The consumer group ID is set to "new-consumer-group"
- Auto offset reset is configured to start from the earliest available message
- The implementation includes error handling and logging capabilities
Feel free to submit issues and enhancement requests.
This project is licensed under the MIT License - see the LICENSE file for details.