Welcome to the Notification Service project! This project demonstrates a notification system using ASP.NET Core, Kafka, and WebSocket (SignalR). The system is designed to produce notifications via Kafka and broadcast them to connected clients using WebSocket.
final-video.mp4
The architecture of this notification service is as follows:
- Kafka Producer Module: Sends notifications to Kafka topics.
- Kafka Consumer Module: Listens to Kafka topics and consumes notifications.
- WebSocket (SignalR): Broadcasts consumed notifications to connected clients in real-time.
- Kafka Integration: Efficient message queuing and delivery.
- SignalR: Real-time communication with WebSocket.
- Scalable Architecture: Easily extendable for additional services or clients.
- ASP.NET Core: Modern web framework for building robust applications.
Before you begin, ensure you have the following installed:
- .NET 8 SDK
- Kafka (setup a Kafka broker)
- SignalR (SignalR)
-
Clone the repository:
git clone https://github.com/your-username/notification-service.git cd notification-service -
Install dependencies:
dotnet restore
-
Update the
appsettings.jsonwith your Kafka configuration:{ "Kafka": { "BootstrapServers": "your-kafka-bootstrap-server" } } -
Run the application:
dotnet run
- Program.cs: Configures and runs the ASP.NET Core application.
- ProducerService.cs: Implements Kafka producer logic.
- ConsumerService.cs: Implements Kafka consumer logic and uses SignalR for broadcasting messages.
- ChatHub.cs: Defines the SignalR hub for WebSocket communication.
- NotificationUpdateRequest.cs: Model for notification messages.
Ensure your appsettings.json contains the necessary Kafka configuration:
{
"Kafka": {
"BootstrapServers": "localhost:9092"
}
}To send a notification, make a POST request to the NotificationController with the following JSON payload:
{
"id": 1,
"deviceId": "device123",
"warningLevel": "High",
"notificationMessage": "Temperature exceeded threshold"
}Connect to the SignalR hub at /chatHub to receive real-time notifications. Use the ReceiveMessage event to handle incoming notifications.
-
Kubernetes Deployment: Future updates will be deployed to Kubernetes for better scalability. This setup allows different pods to manage WebSocket connections, enabling targeted notifications to specific devices.
-
Dead Letter Queue Implementation: I'll introduce a dead letter queue to handle issues such as message deregistration, broken messages, or producer shutdowns. This ensures messages that cannot be processed are not lost.
-
Consumer-Side Offset Management: I plan to implement a pre-configured business logic on the consumer side to automatically commit offsets. This means that if a message is consumed but an error occurs during processing, the system will retry the message to ensure it is processed correctly.
Contributions are welcome! Please fork this repository and submit pull requests.
- Fork the repository
- Create a feature branch (
git checkout -b feature-branch) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature-branch) - Create a new Pull Request
