How neiserdeveloper/ms-chat-socket works
Project Type and Purpose
• This is a standalone chat microservice exposing WebSocket endpoints for real-time messaging.
• It does not include a UI, but rather assumes external clients (web, mobile) will open WebSocket connections.
• The core capabilities: configure WebSocket handshake, accept/route chat messages via a simple broker, and push messages back to subscribers.
File Structure
• src/main/java/com/chat/socket/MsChatSocketApplication.java – Spring Boot entry point.
• configuration/WebSocketConfiguration.java – sets up STOMP/WebSocket endpoints and message broker.
• controller/WebSocketController.java – @MessageMapping handlers that receive and broadcast ChatMessage DTOs.
• dto/ChatMessage.java – the domain model for each chat payload.
• application.properties – broker configuration (e.g. destination prefixes, allowed origins).
• No persistence layer or external broker libraries shown, so likely using Spring’s in-memory broker.
README for Additional Insights
• Describes the project as a “Microservicio chat con Websocket en JAVA 17 con Spring Boot.”
• Focus is on a single microservice that uses Spring WebSocket support for real-time chat.
Main Components and Their Interactions
a. Clients (Web or Mobile)
– Connect via WebSocket (STOMP) to the chat endpoint.
b. API Gateway / Load Balancer (optional for production)
– Routes incoming WebSocket handshake requests to one of the service instances.
c. MsChatSocket Microservice
– WebSocket Configuration Component
• Exposes STOMP endpoint (e.g., /ws-chat)
• Configures message broker (in-memory or external)
– WebSocket Controller
• Listens on application destinations (e.g., /app/chat.send)
• Broadcasts to subscriptions (e.g., /topic/public)
– ChatMessage DTO
• Defines the payload schema for chat events.
d. Message Broker
– In-memory (Spring’s SimpleBroker) or external (RabbitMQ, Redis)
– Routes messages between publisher (controller) and subscribers (clients).
e. Monitoring / Logging (optional)
– Spring Actuator, logs for health, metrics, and trace.
Architectural Patterns & Principles
• Microservice — single responsibility (real-time chat).
• Event-driven / Pub-Sub — clients subscribe to topics; controller publishes events.
• Layered design — configuration, controller, DTO layers.
• Scalability — stateless service instances managed behind a load balancer.
• Clear component names and roles.
– Connection setup (WebSocket handshake).
– Message publish and broadcast paths.
– External actors (clients, LB)
– Service internals (config, controller, DTO)
– Infrastructure (broker)