-
Notifications
You must be signed in to change notification settings - Fork 24
[황지인] sprint12 #311
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 #311
The head ref may contain hidden characters: "\uD669\uC9C0\uC778-sprint12"
Conversation
- 첨부파일이 없는 단순 텍스트 메시지인 경우 STOMP를 통해 메시지를 전송할 수 있는 컨트롤러
- 이벤트 유실 복원을 위해 SSE 메시지를 저장하는 컴포넌트를 구현
- default.conf 추가 - Dockerfile 추가
|
변경 사항이 너무 많이 잡혀서 리뷰하기가 힘들어요 ㅠㅠ |
넵!! 베이스 수정했습니다! |
ssjf409
left a comment
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.
다른 코드에서는 딱히 코멘트 달게 없었습니다. 고생하셨습니다.
| public List<SseEmitter> findAllByUserId (UUID userId) { | ||
| List<SseEmitter> list = data.get(userId); | ||
| if (list == null) { | ||
| return List.of(); | ||
| } | ||
| synchronized (list) { | ||
| return List.copyOf(list); | ||
| } | ||
| } | ||
|
|
||
| // emitter 제거 | ||
| public void delete(UUID userId, SseEmitter emitter) { | ||
| List<SseEmitter> list = data.get(userId); | ||
| if(list == null) { | ||
| return; | ||
| } | ||
| synchronized (list) { | ||
| list.remove(emitter); | ||
| if (list.isEmpty()) { | ||
| data.remove(userId, list); | ||
| } | ||
| } | ||
| } |
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.
findAllByUserId, delete랑 data.get 호출해서 list를 가져오는 순간 동시성이 깨집니다.
이 부분을 computeIfPresent로 해결 하시면 좋을거 같아요.
기본 요구사항
웹소켓 구현하기
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를 전송해 이벤트 유실 복원이 가능하도록 해야 합니다.새로운 알림 이벤트 전송
파일 업로드 상태 변경 이벤트 전송
채널 갱신 이벤트 전송
사용자 갱신 이벤트 전송
배포 아키텍처 구성하기
Reverse Proxy/api/*,/ws/*요청은 Backend 컨테이너로 프록시 처리합니다./usr/share/nginx/html등)에 복사하세요.3000번 포트를 통해 접근할 수 있어야 합니다.BackendReverse Proxy를 통해/api/*,/ws/*요청이 이 서버로 전달됩니다.DB,Memory DB,Message BrokerBackend컨테이너가 접근 가능한 다음의 인프라 컨테이너들을 구성하세요주요 변경사항
스크린샷
멘토에게
''배포 아키텍처 구성하기'' 파트에서 생성된 Spring Boot 인스턴스가 자꾸 재실행 되는 문제가 있어서 해결중입니다.
볼륨으로 넣어둔 로그를 확인해봤을 때