Open
Conversation
This reverts commit e0752c4.
joonfluence
reviewed
Nov 12, 2025
| import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; | ||
|
|
||
| @Configuration | ||
| @EnableWebSocketMessageBroker // STOMP 사용 활성화 |
joonfluence
reviewed
Nov 12, 2025
Comment on lines
+12
to
+22
| @Controller | ||
| @RequiredArgsConstructor | ||
| public class MessageWebSocketController { | ||
|
|
||
| private final MessageService messageService; | ||
|
|
||
| @MessageMapping("/messages") | ||
| public void sendMessage(MessageCreateRequest message) { | ||
| messageService.create(message, java.util.Collections.emptyList()); | ||
| } | ||
| } |
joonfluence
reviewed
Nov 12, 2025
Comment on lines
+14
to
+25
| //public class WebSocketRequiredEventListener { | ||
| // | ||
| // private final SimpMessagingTemplate messagingTemplate; | ||
| // | ||
| // // 메세지 커밋 이후 | ||
| // @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
| // public void handleMessage(MessageCreatedEvent event) { | ||
| // MessageDto messageDto = event.getData(); | ||
| // UUID channelId = messageDto.channelId(); | ||
| // | ||
| // messagingTemplate.convertAndSend("/sub/channels." + channelId + ".messages", messageDto); | ||
| // } |
joonfluence
reviewed
Nov 12, 2025
| @Repository | ||
| public class SseMessageRepository { | ||
|
|
||
| private final ConcurrentLinkedDeque<UUID> eventIdQueue = new ConcurrentLinkedDeque<>(); |
Collaborator
There was a problem hiding this comment.
이벤트 순서 보장을 위한 Queue 사용
joonfluence
reviewed
Nov 12, 2025
| public class SseMessageRepository { | ||
|
|
||
| private final ConcurrentLinkedDeque<UUID> eventIdQueue = new ConcurrentLinkedDeque<>(); | ||
| private final Map<UUID, SseMessage> messages = new ConcurrentHashMap<>(); |
joonfluence
reviewed
Nov 12, 2025
Comment on lines
+37
to
+49
| // SseEmitter 객체를 생성 | ||
| public SseEmitter connect(UUID receiverId, UUID lastEventId) { | ||
| SseEmitter emitter = createEmitter(receiverId); | ||
| if (lastEventId != null) { | ||
| senderPool.execute(() -> | ||
| restoreEvents(emitter, receiverId, lastEventId) | ||
| ); | ||
| } | ||
|
|
||
| ping(emitter, receiverId, "connect", lastEventId); | ||
|
|
||
| return emitter; | ||
| } |
joonfluence
reviewed
Nov 12, 2025
Collaborator
There was a problem hiding this comment.
docker-compose 설정 완료 (nginx 제외)
joonfluence
reviewed
Nov 12, 2025
Comment on lines
+87
to
+91
| // Time-based cleanup - run every hour | ||
| @Scheduled(fixedRate = 3600000) // 1 hour | ||
| public void cleanupOldMessages() { | ||
| Instant cutoff = Instant.now().minusSeconds(MAX_AGE_HOURS * 3600); | ||
| int removed = 0; |
joonfluence
reviewed
Nov 12, 2025
Comment on lines
+18
to
+29
| @RequiredArgsConstructor | ||
| public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { | ||
|
|
||
| private final JwtAuthenticationChannelInterceptor jwtAuthenticationChannelInterceptor; | ||
|
|
||
| @Override | ||
| public void configureMessageBroker(MessageBrokerRegistry config) { | ||
| // 서버가 클라이언트로 메시지를 보낼 때 사용하는 prefix (subscribe) | ||
| config.enableSimpleBroker("/sub"); | ||
| // 클라이언트가 서버로 메시지를 보낼 때 사용하는 prefix (publish) | ||
| config.setApplicationDestinationPrefixes("/pub"); | ||
| } |
Collaborator
There was a problem hiding this comment.
WebSocketMessageBrokerConfigurer 통해 HTTP 요청 간 JWT 인증 수행
joonfluence
reviewed
Nov 12, 2025
| - "8081:8080" | ||
| deploy: | ||
| mode: replicated | ||
| replicas: 3 # 복제 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
기본 구현사항
웹소켓 구현하기
SSE 구현하기
GET /api/sse배포 아키텍처 구성하기
심화
웹소켓 인증/인가 처리하기
분산 환경 배포 아키텍처 구성하기
질문 답변