Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:A616567126 GPT WEB JAVA Multi Channel Message Delivery

From Leeroopedia
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 + userId key 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: SseEmitterServer manages SSE connections; WebSocketServer manages WS sessions

Practical Guide

The repository implements this in SendMessageUtil:

  1. sendMessage(Long userId, Object message) — reads USER_CLIENT + userId from Redis
  2. If isMobile == 1: delegates to WebSocketServer.sendInfo(userId, message)
  3. If isMobile == 0 (or null): delegates to SseEmitterServer.sendMessage(userId, message)
  4. The isMobile flag is set in JwtUtil.getTokenString() during token creation

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment