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

Implementation:A616567126 GPT WEB JAVA SseController

From Leeroopedia
Knowledge Sources
Domains SSE, Real_Time_Communication
Last Updated 2026-10-13 00:00 GMT

Overview

Concrete REST controller for establishing and closing Server-Sent Events (SSE) connections for real-time message delivery to authenticated users.

Description

The SseController exposes two GET endpoints under `/sse`: `/connect/{userId}` creates an SSE connection after validating the user's JWT token from Redis, and `/close/{userId}` removes the SSE connection. It delegates connection management to `SseEmitterServer` and uses `RedisUtil` for token validation.

Usage

Use this controller when a client needs to establish a persistent SSE connection for receiving real-time AI chat responses, or when closing an existing connection.

Code Reference

Source Location

Signature

@RestController
@RequestMapping("/sse")
public class SseController {

    @GetMapping("/connect/{userId}")
    public SseEmitter connect(@PathVariable Long userId);

    @GetMapping("/close/{userId}")
    public B<String> close(@PathVariable("userId") Long userId);
}

Import

import com.intelligent.bot.api.sse.SseController;

I/O Contract

Inputs

Name Type Required Description
userId Long Yes User ID from path variable

Outputs

Name Type Description
connect returns SseEmitter SSE emitter for streaming (null if not authenticated)
close returns B<String> Success response with "连接关闭"

Usage Examples

Establishing SSE Connection

// GET /sse/connect/12345
// Authorization: Bearer <jwt-token>

// Response: text/event-stream
// Server returns SseEmitter for streaming messages

Closing SSE Connection

// GET /sse/close/12345

// Response:
// { "status": 200, "message": "操作成功", "data": "连接关闭" }

Related Pages

Page Connections

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