A .NET 10 application for consuming and producing user events via Apache Kafka with Avro serialization and Schema Registry.
- π’ .NET 10 SDK - Download
- π³ Docker - Download
- π³ Docker Compose - Included with Docker Desktop (or install separately)
- π₯οΈ macOS/Linux/Windows with command-line terminal support
# Check .NET version
dotnet --version
# Check Docker version
docker --version
# Check Docker Compose version
docker compose versionUserEventsApp/
βββ UserEvents.App/ # Main console application
βββ UserEvents.Infra/ # Infrastructure (Kafka producer/consumer)
βββ UserEvents.Models/ # Data models and configuration
βββ docker-compose.yml # Docker services configuration
βββ README.md # This file
- π UserEvents.App: Entry point that runs the consumer service
- βοΈ UserEvents.Infra: Contains Kafka producer/consumer implementations
- π¦ UserEvents.Models: Contains data models (UserCreatedEvent), configurations, and Avro schemas
- π³ Docker Compose: Manages Zookeeper, Kafka, and Schema Registry services
Start the required infrastructure services (Kafka, Zookeeper, Schema Registry):
docker compose up -dThis will:
- Start Zookeeper (port 2181)
- Start Kafka broker (ports 9092, 9101)
- Start Schema Registry (port 8081)
- Automatically create the
user-eventstopic
Verify services are running:
docker compose pscd UserEventsApp
dotnet builddotnet run --project UserEvents.App/UserEvents.App.csprojThe application will:
- Load configuration from
appsettings.json - Connect to Kafka broker at
localhost:9092 - Subscribe to the
user-eventstopic - Listen for messages and process them
Located in UserEvents.App/appsettings.json:
{
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "File",
"Args": {
"path": "Logs/log-.txt",
"rollingInterval": "Day"
}
}
]
},
"KafkaConfig": {
"BootstrapServers": "localhost:9092",
"Topic": "user-events",
"ConsumerGroupId": "user-events-consumer-group",
"SchemaRegistryUrl": "http://localhost:8081"
}
}Configuration Options:
BootstrapServers: Kafka broker addressTopic: Kafka topic name for user eventsConsumerGroupId: Consumer group identifierSchemaRegistryUrl: Schema Registry endpoint for Avro schemas
var userCreatedEvent = new UserCreatedEvent(
UserId: "user-123",
UserName: "john_doe",
UserEmail: "john@example.com",
CreatedAt: DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
);The UserEventsConsumerService has the IEventProducer<string, UserCreatedEvent> injected. Example:
await producer.ProduceAsync("user-123", userCreatedEvent);The producer will:
- Serialize the event to Avro format
- Register the schema with Schema Registry if needed
- Publish the message to the
user-eventstopic
The application uses four main services:
- Image: confluentinc/cp-zookeeper:7.5.0
- Port: 2181
- Purpose: Manages Kafka cluster coordination
- Image: confluentinc/cp-kafka:7.5.0
- Ports: 9092 (external), 9101 (internal)
- Features:
- Auto-create topics enabled
- 24-hour log retention
- 1 partition, 1 replication factor
- Image: confluentinc/cp-schema-registry:7.5.0
- Port: 8081
- Purpose: Manages Avro schemas for Kafka messages
- Purpose: Automatically creates the
user-eventstopic on startup
All services include health checks:
# View service health status
docker compose ps# Start services in the background
docker compose up -d
# View logs for all services
docker compose logs -f
# View logs for a specific service
docker compose logs -f kafka
# Stop all services
docker compose down
# Remove all data and containers
docker compose down -v
# Rebuild services
docker compose up -d --buildThe application uses Serilog for logging:
- π» Console Output: Real-time logs displayed in terminal
- π File Logs: Stored in
Logs/log-YYYY-MM-DD.txtwith daily rotation
Log levels configured:
- Default: Information
- Microsoft: Warning
- System: Warning
View logs:
# Console output (when running the app)
dotnet run --project UserEvents.App/UserEvents.App.csproj
# File logs
tail -f Logs/log-*.txtPress F5 or use the Debug panel to start debugging with breakpoints.
The launch configuration is pre-configured in .vscode/launch.json.
Confluent.Kafka.ConsumeException: Subscribed topic not available: user-events
Solution:
- Ensure Docker services are running:
docker compose ps - Wait for Kafka to be healthy (status: "healthy")
- The
kafka-initservice should create the topic automatically
Error: Unable to connect to broker
Solution:
- Start Docker services:
docker compose up -d - Verify Kafka is running:
docker compose logs kafka - Check bootstrap servers in
appsettings.json
Error retrieving schema from registry
Solution:
- Verify Schema Registry is running:
docker compose ps - Check Schema Registry logs:
docker compose logs schema-registry - Ensure
appsettings.jsonhas correctSchemaRegistryUrl
# Build entire solution
dotnet build
# Build specific project
dotnet build UserEvents.App/UserEvents.App.csproj# Run all tests
dotnet test
# Run specific test project
dotnet test UserEvents.App.Tests/- Confluent.Kafka: Kafka client library
- Serilog: Structured logging
- Microsoft.Extensions.Hosting: Host/dependency injection
- Microsoft.Extensions.Configuration: Configuration management
- Avro: Serialization format (via Confluent)
- Application starts and subscribes to
user-eventstopic - Listens for
UserCreatedEventmessages - Deserializes Avro messages using Schema Registry
- Passes events to
UserCreationHandlerfor processing - Commits offset after successful processing
- Create
UserCreatedEventinstance - Inject
IEventProducer<string, UserCreatedEvent> - Call
ProduceAsync(key, event) - Producer serializes to Avro format
- Message published to Kafka topic
- Consumer Group:
user-events-consumer-groupallows parallel consumers - Partitions: Currently 1 partition (scalable for production)
- Replication Factor: 1 (recommended: 3 for production)
- Auto-commit: Disabled for safer offset management
For production deployment:
- Increase replication factor in docker-compose.yml
- Configure multiple partitions for parallelization
- Update bootstrap servers to point to production Kafka cluster
- Set Schema Registry URL to production registry
- Configure proper logging levels (reduce to Warning/Error)
- Use environment variables for sensitive configuration
- Implement circuit breakers for fault tolerance
- Monitor metrics with Application Insights or similar
We have planned the following improvements and features for future releases:
- π§ͺ Unit Tests - Comprehensive unit test coverage for core services and business logic
- π§ Functional Tests - End-to-end functional testing for Kafka producer/consumer flows
- π Integration Tests - Docker-based integration tests with live Kafka services
- π Code Coverage - Target 80%+ code coverage across all projects
If you'd like to help with testing implementation, we welcome contributions! Please:
- Create an issue with the label
enhancement: testing - Discuss your approach before starting
- Submit a PR with your test implementations
Stay tuned for updates! π
This project is proprietary and confidential. All rights reserved.
Restrictions:
- β Commercial use prohibited without permission
- β Modification prohibited
- β Distribution prohibited
- β Reverse engineering prohibited
β οΈ Unauthorized access strictly forbidden
For licensing inquiries, please contact the copyright holder.
We welcome contributions from developers! Here's how you can contribute to this project:
- Fork the repository
- Clone your fork:
git clone https://github.com/your-username/UserEventsApp.git - Create a feature branch:
git checkout -b feature/your-feature-name - Make your changes and commit:
git commit -m "Add your feature description" - Push to your branch:
git push origin feature/your-feature-name - Open a Pull Request with a clear description of your changes
Code Standards:
- Follow C# naming conventions and .NET best practices
- Write clean, readable code with meaningful comments
- Ensure your code compiles without warnings
Pull Request Process:
- Update the README.md if you change functionality
- Verify the application builds:
dotnet build - Provide a clear description of your changes
- Link any related issues in the PR description
Types of Contributions Welcome:
- π Bug fixes and issue reports
- β¨ New features and enhancements
- π Documentation improvements
- π‘ Performance optimizations
- π¨ UI/UX improvements
- Use the issue tracker to report bugs
- Provide clear reproduction steps
- Include error messages and logs
- Specify your environment (OS, .NET version, Docker version)
# Install dependencies
dotnet restore
# Build the project
dotnet build
# Start Docker services
docker compose up -d- Ask questions in issues or discussions
- Follow the Code of Conduct (be respectful and professional)
- Be patient and constructive with feedback
If you have questions about contributing, please open an issue with the label question or reach out to the maintainers.
Thank you for helping make this project better! π