Chat Service
Real-time chat service for GoodGo platform, built on ASP.NET Core SignalR.
Overview
Chat Service provides real-time communication capabilities in the microservices system with:
- Real-time Communication - ASP.NET Core SignalR with WebSockets/SSE/Long Polling
- Scalability - Redis Backplane or Azure SignalR Service
- User & Group Management - Chat rooms, cross-device user mapping
- AI Integration - Smart chatbot with streaming response
- High Performance - MessagePack protocol
- Resiliency - Auto reconnect, Stateful Reconnect
Requirements
| Requirement |
Version |
| .NET SDK |
10.0.101+ |
| Docker |
24.0+ |
| PostgreSQL |
16+ |
| Redis |
7+ |
Quick Start
1. Configure Environment
2. Run with Docker
3. Run Locally
Feature Details
A. Real-time Communication
| Feature |
Description |
| SignalR Hub |
Central hub handling all real-time connections |
| Multi-Transport |
Auto-select WebSockets → SSE → Long Polling |
| Streaming |
IAsyncEnumerable support for streaming AI responses |
B. Scalability
| Solution |
Use Case |
| Redis Backplane |
On-premise, multi-instance deployment |
| Azure SignalR Service |
Azure cloud, serverless scenarios |
| Sticky Sessions |
Fallback when not using Azure SignalR |
C. User & Group Management
| Feature |
Description |
| Groups |
Group connections by chat room |
| User Mapping |
Map ConnectionId → UserId via Claims |
| Persistent State |
Save group state to database |
D. AI Integration
| Feature |
Description |
| AI Assistant |
In-group chatbot (trigger: @gpt) |
| Streaming Response |
Push response chunks in real-time |
| Context History |
Save chat history for AI context |
E. MessagePack Protocol
F. Resiliency
| Feature |
Description |
| Auto Reconnect |
Client auto-reconnects |
| Stateful Reconnect |
Buffer data during interruption (.NET 8+) |
API Endpoints
HTTP REST APIs
| Method |
Endpoint |
Description |
GET |
/api/v1/rooms |
Get chat room list |
POST |
/api/v1/rooms |
Create new chat room |
GET |
/api/v1/rooms/{id}/messages |
Get message history |
POST |
/api/v1/rooms/{id}/participants |
Add participant |
SignalR Hub Methods
| Method |
Direction |
Description |
SendMessage |
Client → Server |
Send message |
JoinRoom |
Client → Server |
Join room |
LeaveRoom |
Client → Server |
Leave room |
ReceiveMessage |
Server → Client |
Receive message |
UserJoined |
Server → Client |
New user notification |
Health Endpoints
| Endpoint |
Purpose |
/health |
Full status |
/health/live |
Liveness probe |
/health/ready |
Readiness probe |
Configuration
Environment Variables
| Variable |
Description |
Default |
ASPNETCORE_ENVIRONMENT |
Environment |
Development |
DATABASE_URL |
PostgreSQL connection |
- |
REDIS_URL |
Redis connection |
- |
AZURE_SIGNALR_CONNECTION |
Azure SignalR (optional) |
- |
OPENAI_API_KEY |
OpenAI API key (optional) |
- |
appsettings.json
Deployment
Docker Build
Kubernetes
See ARCHITECTURE.md for detailed Kubernetes configuration with Sticky Sessions.
References
License
Proprietary - GoodGo Platform