π© 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 Name | Description | Group ID |
---|---|---|
chat-messages | Receives chat messages from the Chat Service | message-service-group |
π§ Message Processing Flow
π Endpoints Overview
π REST API (HTTP)
Method | Endpoint | Description |
---|---|---|
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"
}