Skip to content

To demonstrate the orchastration of kafka and websocket and imaginary consumer devices to replicate an end-to-end notification service

Notifications You must be signed in to change notification settings

Adarsh1999/Notification-Service

Repository files navigation

Notification Service with Kafka, WebSocket (SignalR), and ASP.NET Core

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.

How our results look like

final-video.mp4

Table of Contents

Architecture

The architecture of this notification service is as follows:

  1. Kafka Producer Module: Sends notifications to Kafka topics.
  2. Kafka Consumer Module: Listens to Kafka topics and consumes notifications.
  3. WebSocket (SignalR): Broadcasts consumed notifications to connected clients in real-time.

Architecture Diagram

Features

  • 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.

Getting Started

Prerequisites

Before you begin, ensure you have the following installed:

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/notification-service.git
    cd notification-service
  2. Install dependencies:

    dotnet restore

Running the Application

  1. Update the appsettings.json with your Kafka configuration:

    {
      "Kafka": {
        "BootstrapServers": "your-kafka-bootstrap-server"
      }
    }
  2. Run the application:

    dotnet run

Key Files

  • 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.

Configuration

Ensure your appsettings.json contains the necessary Kafka configuration:

{
  "Kafka": {
    "BootstrapServers": "localhost:9092"
  }
}

Usage

Sending Notifications

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"
}

Receiving Notifications

Connect to the SignalR hub at /chatHub to receive real-time notifications. Use the ReceiveMessage event to handle incoming notifications.

Future Plans

  1. 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.

  2. 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.

  3. 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.

Contributing

Contributions are welcome! Please fork this repository and submit pull requests.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature-branch)
  3. Commit your changes (git commit -am 'Add new feature')
  4. Push to the branch (git push origin feature-branch)
  5. Create a new Pull Request

About

To demonstrate the orchastration of kafka and websocket and imaginary consumer devices to replicate an end-to-end notification service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages