-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 방을 나가면 전체 WAS 서버에서 기존 연결을 끊을 수 있도록 기능추가
- Loading branch information
Showing
8 changed files
with
153 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...n/java/com/programmers/lime/global/config/chat/message/ChatRoomRemoveSessionListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.programmers.lime.global.config.chat.message; | ||
|
||
import java.util.Set; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import com.programmers.lime.error.BusinessException; | ||
import com.programmers.lime.error.ErrorCode; | ||
import com.programmers.lime.global.config.chat.WebSocketSessionManager; | ||
import com.programmers.lime.redis.chat.ChatSessionRedisManager; | ||
import com.programmers.lime.redis.chat.listener.IChatRoomRemoveSessionListener; | ||
import com.programmers.lime.redis.chat.model.ChatRoomRemoveAllSessionInfo; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ChatRoomRemoveSessionListener implements IChatRoomRemoveSessionListener { | ||
|
||
private final ChatSessionRedisManager chatSessionRedisManager; | ||
|
||
private final WebSocketSessionManager webSocketSessionManager; | ||
|
||
@Override | ||
public void removeAllSession(final ChatRoomRemoveAllSessionInfo chatRoomRemoveAllSessionInfo) { | ||
|
||
Set<String> sessionIdsByMemberAndRoom = chatSessionRedisManager.getSessionIdsByMemberAndRoom( | ||
chatRoomRemoveAllSessionInfo.memberId(), | ||
chatRoomRemoveAllSessionInfo.roomId() | ||
); | ||
|
||
for (String memberSessionId : sessionIdsByMemberAndRoom) { | ||
try { | ||
webSocketSessionManager.closeSession(memberSessionId); | ||
} catch (Exception e) { | ||
throw new BusinessException(ErrorCode.CHAT_SESSION_NOT_FOUND); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...n/java/com/programmers/lime/redis/chat/listener/ChatRoomRemoveAllSessionListenerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.programmers.lime.redis.chat.listener; | ||
|
||
import org.springframework.data.redis.connection.Message; | ||
import org.springframework.data.redis.connection.MessageListener; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.programmers.lime.redis.chat.model.ChatRoomRemoveAllSessionInfo; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ChatRoomRemoveAllSessionListenerImpl implements MessageListener { | ||
|
||
private final RedisTemplate<String, Object> redisTemplate; | ||
|
||
private final IChatRoomRemoveSessionListener chatRoomRemoveSessionListener; | ||
|
||
@Override | ||
public void onMessage(final Message message, final byte[] pattern) { | ||
try { | ||
ChatRoomRemoveAllSessionInfo chatRoomRemoveAllSessionInfo = (ChatRoomRemoveAllSessionInfo)redisTemplate.getValueSerializer() | ||
.deserialize(message.getBody()); | ||
|
||
if (chatRoomRemoveAllSessionInfo == null) { | ||
throw new IllegalStateException("Deserialized message is null. Message deserialization failed."); | ||
} | ||
|
||
chatRoomRemoveSessionListener.removeAllSession(chatRoomRemoveAllSessionInfo); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to process redis message", e); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...rc/main/java/com/programmers/lime/redis/chat/listener/IChatRoomRemoveSessionListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.programmers.lime.redis.chat.listener; | ||
|
||
import com.programmers.lime.redis.chat.model.ChatRoomRemoveAllSessionInfo; | ||
|
||
public interface IChatRoomRemoveSessionListener { | ||
|
||
void removeAllSession(final ChatRoomRemoveAllSessionInfo chatRoomRemoveAllSessionInfo); | ||
} |
10 changes: 10 additions & 0 deletions
10
...ure/src/main/java/com/programmers/lime/redis/chat/model/ChatRoomRemoveAllSessionInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.programmers.lime.redis.chat.model; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ChatRoomRemoveAllSessionInfo( | ||
Long roomId, | ||
Long memberId | ||
) { | ||
} |
20 changes: 20 additions & 0 deletions
20
...c/main/java/com/programmers/lime/redis/chat/publisher/ChatRoomRemoveSessionPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.programmers.lime.redis.chat.publisher; | ||
|
||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.programmers.lime.redis.chat.model.ChatRoomRemoveAllSessionInfo; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ChatRoomRemoveSessionPublisher implements IChatRoomRemoveSessionPublisher { | ||
|
||
private final RedisTemplate<String, Object> redisTemplate; | ||
|
||
public void removeAllSession(final String channel, | ||
final ChatRoomRemoveAllSessionInfo chatRoomRemoveAllSessionInfo) { | ||
redisTemplate.convertAndSend(channel, chatRoomRemoveAllSessionInfo); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../main/java/com/programmers/lime/redis/chat/publisher/IChatRoomRemoveSessionPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.programmers.lime.redis.chat.publisher; | ||
|
||
import com.programmers.lime.redis.chat.model.ChatRoomRemoveAllSessionInfo; | ||
|
||
public interface IChatRoomRemoveSessionPublisher { | ||
void removeAllSession(String channel, ChatRoomRemoveAllSessionInfo chatRoomRemoveAllSessionInfo); | ||
} |