πŸ“© Message Service

Github: github.com/le-minh-duc-dev/chat-system-message-service.git

The Message Service is responsible for persisting chat messages within the Chat System.
It consumes messages from Kafka topics produced by the Chat Service and stores them in a relational database for retrieval and history features.


πŸ“œ Features

  • Kafka Message Consumption
    Listen to Kafka topics and consume incoming chat messages asynchronously.

  • Message Persistence
    Save received messages into the database for long-term storage and chat history reconstruction.

  • Scalable and Fault-Tolerant
    Designed for high throughput, with support for partitioned Kafka topics and consumer groups.

  • Structured Message Model
    Define and enforce message schemas (e.g., sender, receiver, content, timestamp) for consistency.

  • Infinite Scroll & Unseen Messages Support Optimized to support infinite scroll pagination for chat history and "unseen messages" logic using per-user, per-room lastSeen timestamps.


🧰 Technology Stack

  • Spring Boot
  • Spring Kafka
  • Spring Data JPA
  • Spring Data Redis
  • PostgreSQL
  • Apache Kafka
  • Spring Cloud OpenFeign
  • Spring Cloud Netflix Eureka
  • Spring Cloud Config

πŸ“‚ Kafka Listener Overview

Topic NameDescriptionGroup ID
chat-messagesReceives chat messages from the Chat Servicemessage-service-group

🧭 Message Processing Flow


πŸ“‚ Endpoints Overview

🌐 REST API (HTTP)

MethodEndpointDescription
GET/api/v1/messages?chatRoomId={id}&messageId={id}&type={type}Fetch chat messages in infinite scroll mode (older or newer) using messageId as anchor.
GET/api/v1/messages/last_seen?chatRoomId={id}Fetch messages from the user’s last seen timestamp in the given chat room.

πŸ“ Data Contracts

Message Payload (MessageDTO)

{
  "id": "812738129374812160",
  "senderId": "1",
  "roomId": "1",
  "content": "Hello!",
  "type":"GROUP"
  "timestamp": "2025-04-29T15:23:00"
}

InfiniteScroll Messages Payload (InfiniteScrollResult<MessageDTO>)

{
  "data": "[]",
  "hasMoreOnTop": "false",
  "hasMoreOnBottom": "false"
}

πŸ’¬ "Turning ideas into scalable code."

Β© 2025 LΓͺ Minh Đức. Stay curious.