Skip to content
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

[BE] 26.04 웹소켓 코드 수정 #182 #200

Merged
merged 7 commits into from
Nov 27, 2024
Merged

Conversation

sieunie
Copy link
Collaborator

@sieunie sieunie commented Nov 26, 2024

✅ 주요 작업

  • base-stock-socket domain service 추상 클래스 만들어서 관리
  • stock-index-socket, stock-price-socket 서비스 만들어서 각 소켓 서비스마다 하나의 책임을 갖도록 수정
  • 다른 서비스에서 stockSocket 모듈의 서비스를 참조하도록 변경
  • 소켓 구독 횟수를 카운트해서 connection 관리 로직 추가

💭 고민과 해결과정

image

  • 기능이 추가됨에 따라 위 그림과 같이 실시간 체결가를 사용하는 서비스가 너무 많아져 의존성이 복잡해졌습니다. 이를 해결하기 위해, 실시간 체결가를 담당하는 서비스들을 하나로 통합해 관리하도록 구현을 진행했습니다.
    • 소켓 서비스는 크게 실시간 체결가(stock-price-socket.service.ts), 실시간 주가지수(stock-index-socket.service.ts)로 나누어 집니다.
    • 실시간 체결가 서비스에서 detail 페이지, 매수/매도, 마이페이지 자산 부분을 모두 처리하도록 구현했습니다.
  • 실시간 체결가 서비스를 모두 하나의 세션으로 관리하도록 변경함에 따라 소켓 연결 관리 로직을 구현해야 할 필요가 생겼습니다.
    • subscribe를 진행할 때마다 종목에 대해 connection count를 하나씩 늘려주고, unsubscribe를 진행할 때마다 connection count를 하나씩 줄여줍니다.
    • connection count가 0이 될 경우, 실제로 종목 구독을 취소합니다.

@sieunie sieunie added BE 백엔드 SOCKET Socket 구현 REFACTORING 코드 리팩터링 labels Nov 26, 2024
@sieunie sieunie linked an issue Nov 26, 2024 that may be closed by this pull request
@uuuo3o
Copy link
Collaborator

uuuo3o commented Nov 26, 2024

기능이 추가됨에 따라 위 그립과 같이 실시간 체결가를 사용하는 서비스가 너무 많아져 의존성이 복잡해졌습니다. 이를 해결하기 위해, 실시간 체결가를 담당하는 서비스들을 하나로 통합해 관리하도록 구현을 진행했습니다.

*그립 -> 그림 오타있어서 수정했습니당

connection count가 0이 될 경우, 실제로 종목 구독을 취소합니다.

커넥션 카운트로 fe - be 또는 be 내부 로직에서 사용되는지 확인하고, 모든 연결이 끊기면 한투와 연결을 끊는 로직 아이디어가 정말 좋은 거 같아요!

Copy link
Collaborator

@jinddings jinddings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!

};
});
}
// @Sse(':stockCode/today-sse')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 해당 부분은 필요 없어진 컨트롤러인가요? 임시로 삭제 했다가 복구가 안된건가요? 필요 없어진 코드면 지우는게 좋을 것 같습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 프론트분들 소켓 연동되면 비교해보고 SSE로 할지, 소켓으로 할지 결정한 뒤에 결정되면 지우거나 살리거나 할 예정이었습니다...!!

@uuuo3o uuuo3o merged commit 4737a9d into back/main Nov 27, 2024
2 checks passed
@uuuo3o uuuo3o deleted the refactor/socket-#182 branch December 5, 2024 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE 백엔드 REFACTORING 코드 리팩터링 SOCKET Socket 구현
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BE] 26.04 웹소켓 코드 수정
3 participants