Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.jootalkpia.chat_server.config;

import com.jootalkpia.chat_server.config.interceptor.StompConnectInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.messaging.SessionDisconnectEvent;

@Component
@RequiredArgsConstructor
public class SessionEventListener {
private final StompConnectInterceptor stompConnectInterceptor;

@EventListener
public void handleWebSocketDisconnectListener(SessionDisconnectEvent event) {
StompHeaderAccessor headerAccessor = StompHeaderAccessor.wrap(event.getMessage());

stompConnectInterceptor.handleDisconnection(headerAccessor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public void afterSendCompletion(Message<?> message, MessageChannel channel, bool
handleStompCommand(StompHeaderAccessor.wrap(message));
}

public void handleDisconnection(StompHeaderAccessor accessor) {
if (!StompCommand.DISCONNECT.equals(accessor.getCommand())) {
return;
}

handleUserDisconnection(accessor);
}

private boolean hasException(Exception ex) {
return ex != null;
}
Expand All @@ -53,14 +61,6 @@ private void handleConnection(StompHeaderAccessor accessor) {
handleUserConnection(accessor);
}

private void handleDisconnection(StompHeaderAccessor accessor) {
if (!StompCommand.DISCONNECT.equals(accessor.getCommand())) {
return;
}

handleUserDisconnection(accessor);
}

private void handleUserConnection(StompHeaderAccessor accessor) {
String sessionId = accessor.getSessionId();
String userId = accessor.getFirstNativeHeader(HEADER_USER_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.messaging.support.ChannelInterceptor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -45,13 +44,12 @@ public void afterSendCompletion(Message<?> message, MessageChannel channel, bool
handleStompCommand(StompHeaderAccessor.wrap(message));
}

@Transactional
Copy link
Member

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.

@transactional은 저번 PR에서 말씀 주신 부분을 고려 중이라 현재는 삭제한 상태입니다.
RDB의 경우 SAVE라 필요가 없고 Redis의 경우 Rollback은 안되고 같은 커넥션의 공유로 인한 리소스 절약이 주된 이유라 생각해 Redis의 원자성에 대해 학습 후 반영하겠습니다.

public void handleChatUnsubscription(StompHeaderAccessor accessor) {
String sessionId = accessor.getSessionId();
String userId = getUserIdFromSessionId(sessionId);
String channelId = getChannelIdFromSessionId(sessionId);

if (userId != null && !userId.trim().isEmpty()) {
if (userId != null && !userId.trim().isEmpty() && !channelId.equals(DEFAULT_CHANNEL)) {
updateChannelFromSession(sessionId);
removeTabFromChannel(channelId, userId, sessionId);
userChannelRepository.updateLastReadId(
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified src/backend/workspace_server/.gradle/file-system.probe
Binary file not shown.