You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sequenceDiagram
participant Client
participant MW as WebSocketMiddleware
participant JWT as JwtProvider
participant SM as SessionManager
participant Reg as WebSocketConnectionManager
participant SRV as ServerRegistrationService
participant Redis
Client->>MW: WebSocket /ws?token={jwt}
MW->>JWT: ValidateAndExtractUserId(token)
JWT-->>MW: userId
MW->>MW: AcceptWebSocketAsync()
Note over MW: 연결 등록 시작
MW->>Reg: HasLocalConnection(userId)?
alt 기존 로컬 연결 존재
MW->>Reg: UnregisterConnection(userId)
end
MW->>SM: CreateSessionAsync(userId)
SM->>Redis: SET session:user:{userId} (TTL: 30분)
MW->>Reg: RegisterConnection(userId, connection)
Note over Reg: ConcurrentDictionary에 저장
MW->>SRV: SetUserServerAsync(userId, serverId)
SRV->>Redis: SET user:server:{userId} = serverId (TTL: 35분)
MW-->>Client: {"type":"connected"}
MW->>MW: RunSessionLoop() - 세션 유지
Loading
Ping/Pong 하트비트
sequenceDiagram
participant Client
participant MW as WebSocketMiddleware
participant SM as SessionManager
participant Redis
loop 주기적으로
Client->>MW: {"type":"ping"}
MW->>SM: UpdateSessionHeartbeatAsync(userId)
SM->>Redis: EXPIRE session:user:{userId} 30분
MW-->>Client: {"type":"pong"}
end
Loading
HTTP 요청 → 백그라운드 처리 → WebSocket 푸시
sequenceDiagram
participant Client
participant API as ChatController
participant JWT as JwtAuthenticationFilter
participant CS as ChatService
participant Handler as ChatSuccessHandler
participant MB as DistributedMessageBroker
participant Reg as WebSocketConnectionManager
participant Redis
participant RemoteServer
Client->>API: POST /api/v1/chat (Authorization: Bearer {jwt})
API->>JWT: ValidateJWT()
JWT-->>API: userId
API->>CS: EnqueueChatRequestAsync(command)
API-->>Client: 202 Accepted
Note over CS: 백그라운드 파이프라인 처리<br/>(Validation → LLM → TTS)
CS->>Handler: HandleAsync(context)
Handler->>MB: SendToUserAsync(userId, message)
MB->>Reg: HasLocalConnection(userId)?
alt 로컬 연결 존재
MB->>Reg: SendTextAsync(userId, message)
Reg-->>Client: WebSocket 메시지
else 원격 서버에 연결
MB->>Redis: GET user:server:{userId}
Redis-->>MB: targetServerId
MB->>Redis: PUBLISH server:{targetServerId}, message
Redis-->>RemoteServer: 메시지 전달
RemoteServer->>RemoteServer: OnServerMessageReceived()
RemoteServer->>Reg: SendTextAsync(userId, message)
Reg-->>Client: WebSocket 메시지
end
Loading
연결 해제 및 정리
sequenceDiagram
participant Client
participant MW as WebSocketMiddleware
participant Reg as WebSocketConnectionManager
participant SM as SessionManager
participant SRV as ServerRegistrationService
participant Redis
Client->>MW: 연결 종료
MW->>Reg: UnregisterConnection(userId)
Note over Reg: 로컬 ConcurrentDictionary에서 제거
MW->>SM: DeleteSessionAsync(userId)
SM->>Redis: DEL session:user:{userId}
MW->>SRV: RemoveUserServerAsync(userId)
SRV->>Redis: DEL user:server:{userId}
MW->>MW: CloseAsync(WebSocket)
Loading
운영/확장 고려
1. 서버 간 라우팅 (구현 완료)
ServerRegistrationService:
서버 ID 자동 생성: api-server-{hostname}-{pid}-{timestamp} 또는 환경변수 SERVER_ID