-
Notifications
You must be signed in to change notification settings - Fork 16
[안중원] Sprint12 #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 안중원
Are you sure you want to change the base?
[안중원] Sprint12 #171
Conversation
- `connect`: SseEmitter 객체를 생성합니다.
- `send`, `broadcast`: SseEmitter 객체를 통해 이벤트를 전송합니다.
- `cleanUp`: 주기적으로 ping을 보내서 만료된 `SseEmitter` 객체를 삭제합니다.
- `ping`: 최초 연결 또는 만료 여부를 확인하기 위한 용도로 더미 이벤트를 보냅니다.
- emitter가 아직 살아있는지 확인용 더미 이벤트 ping 구현
- 사용자 생성, 업데이트, 삭제
- 요청 경로 불일치 문제 해결(/삭제)
- backend 컨테이너를 못 찾아서 스프링부트 연결 안되는 문제 해결(컨테이너 이름 명시적 지정/ container_name 사용)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request implements WebSocket and SSE (Server-Sent Events) functionality for real-time communication, along with a Docker Compose-based deployment architecture. The changes include WebSocket message handling, SSE for real-time notifications, and infrastructure setup for production deployment.
Key Changes:
- WebSocket configuration with STOMP protocol for real-time messaging
- SSE implementation for server-to-client event streaming (notifications, file upload status, channel/user updates)
- Docker Compose setup with Nginx reverse proxy, PostgreSQL, Redis, and Kafka
- S3 and local storage implementations for binary content
Reviewed Changes
Copilot reviewed 193 out of 199 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/resources/application.yaml | Main application configuration including Kafka, Redis, and storage settings |
| src/main/resources/application-dev.yaml | Development environment configuration |
| src/main/resources/application-prod.yaml | Production environment configuration |
| src/main/resources/schema.sql | Database schema definitions for all entities |
| src/main/java/com/sprint/mission/discodeit/service/basic/* | Service implementations for user, message, channel, SSE, and binary content management |
| src/main/java/com/sprint/mission/discodeit/storage/* | Storage abstraction layer with S3 and local implementations |
| src/test/java/com/sprint/mission/discodeit/**/* | Comprehensive test coverage for services, controllers, repositories, and security |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
| public void handleMessage(MessageCreatedEvent event) { | ||
| log.debug("# 웹 소켓 브로드캐스트 시작"); | ||
| Message content = messageRepository.findById(event.messageId()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기 레퍼지토리에서 직접 조회해오는 형태가 아니라 파라미터로 받은 event 에서 꺼내오는 형태로 구현하면 될것 같아요!
|
심화기능에 대한 구현이 누락된 것 같습니다 ! 추가학습하여 꼭 공부해보시기 바랍니다 |
웹소켓 구현하기
spring-boot-starter-websocket의존성을 추가하세요.implementation 'org.springframework.boot:spring-boot-starter-websocket'웹소켓 메시지 브로커 설정
메모리 기반
SimpleBroker를 사용하세요./sub으로 설정하세요./pub으로 설정하세요./ws로 설정하고,SockJS연결을 지원해야 합니다.첨부파일이 없는 단순 텍스트 메시지인 경우 STOMP를 통해 메시지를 전송할 수 있도록 컨트롤러를 구현하세요.
/pub/messages엔드포인트에 메시지를 전송할 수 있어야 합니다.@MessageMapping을 활용하세요.MessageCreateRequest를 그대로 활용합니다.첨부파일이 포함된 메시지는 기존의 API (
POST /api/messages)를 그대로 활용합니다.클라이언트는 채널 입장 시 웹소켓으로
/sub/channels.{channelId}.messages를 구독해 메시지를 수신합니다.이를 고려해 메시지가 생성되면 해당 엔드포인트로 메시지를 보내는 컴포넌트를 구현하세요.
MessageCreatedEvent를 통해 새로운 메시지 생성 이벤트를 확인하세요.SimpMessagingTemplate를 통해 적절한 엔드포인트로 메시지를 전송하세요.SSE 구현하기
클라이언트에서 SSE 연결을 위한 엔드포인트를 구현하세요.
GET /api/sse사용자별 SseEmitter 객체를 생성하고 메시지를 전송하는 컴포넌트를 구현하세요.
connect: SseEmitter 객체를 생성합니다.send,broadcast: SseEmitter 객체를 통해 이벤트를 전송합니다.cleanUp: 주기적으로 ping을 보내서 만료된SseEmitter객체를 삭제합니다.ping: 최초 연결 또는 만료 여부를 확인하기 위한 용도로 더미 이벤트를 보냅니다.SseEmitter객체를 메모리에서 저장하는 컴포넌트를 구현하세요.ConcurrentMap: 스레드 세이프한 자료구조를 사용합니다.List<SseEmitter>: 사용자 당 N개의 연결을 허용할 수 있도록 합니다. (예: 다중 탭)이벤트 유실 복원을 위해 SSE 메시지를 저장하는 컴포넌트를 구현하세요.
LastEventId를 전송해 이벤트 유실 복원이 가능하도록 해야 합니다.새 알림이 생성되었을 때 클라이언트에 이벤트를 전송하세요.
클라이언트는 이 이벤트를 수신하면 알림 목록에 알림을 추가합니다.
이벤트 명세
notifications.createdNotificationDto파일 업로드 상태가 변경될 때 이벤트를 발송하세요.
클라이언트는 해당 상태를 수신하면 파일 상태 UI를 다시 렌더링합니다.
이벤트 명세
binaryContents.updatedBinaryContentDto채널 정보가 변경될 때, 이벤트를 발송하세요.
클라이언트는 해당 이벤트를 수신하면 채널 UI를 다시 렌더링합니다.
이벤트 명세
channels.createdorupdatedordeletedChannelDto사용자 정보 또는 로그인 상태가 변경될 때, 이벤트를 발송하세요.
클라이언트는 해당 이벤트를 수신하면 사용자 UI를 다시 렌더링합니다.
이벤트 명세
users.createdorupdatedordeletedUserDto배포 아키텍처 구성하기
다음의 다이어그램에 부합하는 배포 아키텍처를 Docker Compose를 통해 구현하세요.

Reverse Proxy/api/*,/ws/*요청은 Backend 컨테이너로 프록시 처리합니다./usr/share/nginx/html등)에 복사하세요.3000번 포트를 통해 접근할 수 있어야 합니다.BackendReverse Proxy를 통해/api/*,/ws/*요청이 이 서버로 전달됩니다.DB,Memory DB,Message BrokerBackend컨테이너가 접근 가능한 다음의 인프라 컨테이너들을 구성하세요