Skip to content

ZaTribune/springboot-activemq-sse-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ActiveMQ SSE Real-Time Chat Application

A demo real-time messaging system demonstrating JMS (Java Message Service) with Server-Sent Events (SSE) for instantaneous message delivery to connected browser clients.

Java Spring Boot ActiveMQ

overview

Features

  • Real-time Message Delivery via Server-Sent Events (SSE)
  • Asynchronous Messaging using Apache ActiveMQ Artemis
  • Message Persistence with H2 filesystem database
  • Queue-based Access Control with role-based permissions
  • XSS Prevention with message sanitization
  • Multi-user Support with Spring Security authentication

Why do we need both (Message broker & Database)?

  • Without the Broker:
    • New messages would require clients to constantly poll the database (inefficient).
    • No real-time updates via SSE.
    • Heavy database load.
  • Without the Database:
    • Messages are lost when the broker restarts.
    • No message history to view.
    • Can't search past conversations.
    • New clients can't see previous messages.

Getting Started

Access the application

Testing Demo Credentials

Username Password Queues
user1@gmail.com pass Messaging, Admin
user2@gmail.com pass Messaging
user3@gmail.com pass Messaging, Support

Key Workflow

User Types Message 
    ↓
Submit Form (AJAX)
    ↓
MessagingService (Save to DB + Send to JMS)
    ↓
ActiveMQ Queue
    ↓
SseService (Notifies Connected Clients)
    ↓
Browser SSE Listener (insertMessageWithMetadata)
    ↓
Chat UI Updated (Message Appears at Bottom)

API Endpoints

Method Endpoint Description
GET /home Dashboard
GET /queues List accessible queues
GET /queues/{queue} View queue messages
POST /queues/send Send message to queue
GET /sse/infinite/{queue} SSE endpoint
GET /queues/{queue}/search Search messages
POST /login User authentication
POST /logout User logout
GET /registration Registration page
POST /registration/create Create user account

Troubleshooting

Issue: Messages not appearing

  • Check browser console for errors (F12)
  • Verify user has READ access to queue
  • Ensure ActiveMQ is running

Issue: ActiveMQ console not accessible

  • Verify Docker container is running: docker ps
  • Check ActiveMQ logs: docker logs activemq

Issue: Database locked

  • Delete ./data/chatdb.mv.db and restart
  • Or use mvn clean to reset

Author

Linkedin

About

A demo application that demonstrates the use of JMS Messaging with Server Sent Events to deliver push messages to browser clients.

Topics

Resources

Stars

Watchers

Forks

Contributors