Principle:A616567126 GPT WEB JAVA Multi Channel Message Delivery
| Knowledge Sources | |
|---|---|
| Domains | Real_Time_Communication, Web_Protocols |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Pattern that routes real-time messages to the appropriate client transport (SSE for web, WebSocket for mobile) based on the user's client type stored in Redis.
Description
When a platform serves both web and mobile clients, the server must deliver real-time messages through the transport each client supports. Web browsers use Server-Sent Events (SSE) via SseEmitter, while mobile clients use WebSocket.
This repository implements a unified SendMessageUtil that checks the user's isMobile flag (stored in Redis at login time) and routes to either SseEmitterServer.sendMessage() or WebSocketServer.sendInfo(). This abstraction lets all services (GPT streaming, MJ notifications, SD results) push messages without knowing the client's transport.
Usage
Use this principle when:
- Serving both web and mobile clients from the same backend
- Needing a unified message delivery interface across transports
- Storing client type at login for later routing decisions
Theoretical Basis
Transport Routing:
# Abstract algorithm (NOT real implementation)
def send_message(user_id, message):
is_mobile = redis.get("user_client:" + user_id) or 0
if is_mobile == 1:
websocket_server.send(user_id, message)
else:
sse_emitter_server.send(user_id, message)
Key Properties:
- Redis-stored client type:
USER_CLIENT + userIdkey set at JWT creation time - Default to web: If no Redis entry exists, defaults to
isMobile = 0(SSE) - Transport-agnostic callers: All services call
SendMessageUtil.sendMessage()without knowing the transport - Connection management:
SseEmitterServermanages SSE connections;WebSocketServermanages WS sessions
Practical Guide
The repository implements this in SendMessageUtil:
sendMessage(Long userId, Object message)— readsUSER_CLIENT + userIdfrom Redis- If
isMobile == 1: delegates toWebSocketServer.sendInfo(userId, message) - If
isMobile == 0(or null): delegates toSseEmitterServer.sendMessage(userId, message) - The
isMobileflag is set inJwtUtil.getTokenString()during token creation