Skip to content

charan2004/websocket-noticeboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Notice Broadcasting Platform

A secure, scalable, and horizontally distributed Real-Time Notice Broadcasting system built with Java 17, Spring Boot 3, and WebSockets (STOMP).

Architecture Details

This platform fulfills the strict requirement of zero persistence for messages:

  • Like a live sports broadcast, only currently connected users receive messages.
  • Offline users do not receive missed messages upon reconnecting.
  • Users and Departments are persisted in PostgreSQL.
  • Notices strictly pass-through via memory and Redis.

Tech Stack

  • Backend: Java 17, Spring Boot 3.2.x
  • Security: Spring Security 6, JWT (io.jsonwebtoken 0.11.5)
  • Database: PostgreSQL (Hibernate & Spring Data JPA)
  • High Availability (WebSocket Scaling): Redis PubSub
  • Build Tool: Maven

Core Concepts

1. JWT Authentication

Provides stateless REST API security. The JWT is validated in the REST Filter chain, as well as a specialized JwtChannelInterceptor for STOMP CONNECT frames.

Identity Standardization: To ensure private messaging works reliably, the WebSocket Principal identity is mapped strictly to the user's email literal string.

2. Scaling STOMP horizontally with Redis

Standard STOMP relies on in-memory mapping. When scaled to Multiple Nodes, a user connected to Node A wouldn't receive a broadcast from Node B. This system utilizes Redis Pub/Sub to solve this:

  • Notice Topic (notice_broadcast_topic): Every broadcast is published here. All nodes listen and push to their local connected users.
  • ACK Topic (notice_ack_topic): Every view acknowledgement (ACK) from a client is published here. This allows view count synchronization across the entire cluster.

3. Live View Count (👁️)

This platform implements a real-time view counting feature with zero persistence:

  • When a client receives a message, they send a ViewAck via STOMP to /app/view.
  • The server publishes this ACK to Redis.
  • The ViewService deduplicates viewers in-memory (using ConcurrentHashMap).
  • Updated counts are streamed back to the original sender's private queue (/user/queue/view-count).

4. RBAC & Identity

  • Roles: ADMIN, TEACHER, STUDENT.
  • Departments: MATHS, PHYSICS, COMPUTER_SCIENCE.
  • Identity: Users have a BIGINT (Long) primary key for REST operations and a UUID for secondary identification. Email remains the unique login identifier.

5. STOMP Routing & Role Constraints

  • /topic/live/all (Global) -> Only ADMIN can send here.
  • /topic/live/department/{dept} (Departmental) -> ADMIN or TEACHER (only to their own department).
  • /user/queue/live (Private) -> Users receive their own private messages here.
  • /user/queue/view-count (View Updates) -> Broadcasters receive live 👁️ updates here.

Getting Started

Prerequisites

  • Java 17+
  • PostgreSQL listening at localhost:5432 with a noticeboard database (User/Pass: postgres/191204).
  • Redis running on localhost:6379.

Environmental Variables

You can override standard variables in application.yml via environment:

  • DB_URL, DB_USER, DB_PASSWORD
  • REDIS_HOST, REDIS_PORT, REDIS_PASSWORD
  • JWT_SECRET, JWT_EXPIRATION_MS

Build & Run

mvn clean install
mvn spring-boot:run

The server starts on port 8081. Access the UI at: http://localhost:8081/login.html


Web UI Dashboard

The platform includes a built-in Vanilla HTML/JS dashboard:

  1. Login (/login.html): Authenticate with email and password.
  2. Signup (/signup.html): Create a new account with a specific Role and Department.
  3. Home (/dashboard.html):
    • Student View: Read-only panels for Global, Departmental, and Private notices.
    • Admin/Teacher View: Panel to author broadcasts and a "Sent Messages" panel with live View Count (👁️) updates.

Testing Guide

1. Browser-Based Testing (Recommended)

  1. Signup/Login: Go to /login.html and create a Teacher account.
  2. Student View: Open an incognito window and create a Student account (same department).
  3. Broadcast: As the Teacher, send a "Department" notice.
  4. Verify:
    • The Student receives the message instantly.
    • The Teacher's dashboard shows 👁️ 1 immediately after the Student views it.

2. Manual API Testing (REST)

Login Endpoint: POST /api/auth/login

{ "email": "admin@school.com", "password": "password123" }

Response: Returns token and id (BIGINT).

Broadcasting:

Action Endpoint Auth
Global POST /api/notices/broadcast/all ADMIN
Private POST /api/notices/private/{id} ADMIN/TEACHER

3. WebSocket Connection (STOMP)

Connect URL: ws://localhost:8081/ws-noticeboard (Requires Authorization: Bearer <token>)

Subscriptions:

  • /topic/live/all
  • /topic/live/department/{DEPT}
  • /user/queue/live
  • /user/queue/view-count (Broadcasters only)

About

Java SpringBoot STOMP based websocket module with RBAC to broadcast, multicast and unicast messages.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors