-
Notifications
You must be signed in to change notification settings - Fork 3
fix : 웹소켓 연결 후 일정 시간이 지나면 ActiveMQ와의 연결이 끊기는 문제 해결 #178
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
Conversation
- 일정 시간동안 아무런 데이터가 오가지 않으면 웹소켓의 메시지 브로커(ActiveMQ)가 자동으로 연결을 끊어버림 - heart beat 기능을 애플리케이션 단에 직접 구현함 - idle timeout 이슈를 해결하기 위해 activemq가 실행되고 있는 ec2 인스턴스의 인바운드 규칙을 편집함
Walkthrough새 Spring 컴포넌트 StompKeepAliveScheduler를 추가하여, @scheduled(fixedDelay=15000)로 15초 간격으로 STOMP 주제 /topic/keep-alive 에 "ping" 메시지를 SimpMessagingTemplate.convertAndSend로 전송합니다. ActiveMQ TTL(20초)보다 짧게 설정되었음이 주석으로 명시되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant CRON as Spring Scheduler
participant SKS as StompKeepAliveScheduler
participant SMT as SimpMessagingTemplate
participant BROKER as STOMP Broker
participant SUB as Subscribers
Note over CRON: fixedDelay = 15s (실행 종료 후 15초 대기)
CRON->>SKS: 트리거 sendKeepAliveMessage()
SKS->>SMT: convertAndSend("/topic/keep-alive", "ping")
SMT->>BROKER: STOMP 전송
BROKER-->>SUB: 메시지 전달 ("ping")
Note over BROKER,SUB: TTL 20s 내 keep-alive 수신
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/main/java/org/ezcode/codetest/infrastructure/scheduler/StompKeepAliveScheduler.java (3)
16-18: 간격을 프로퍼티로 노출하고 fixedRate+initialDelay로 드리프트/GC 지연을 완충하세요.현재 fixedDelay=15초는 브로커 타임아웃(주석 상 20초) 대비 버퍼가 얇습니다. GC/네트워크 지연이 끼면 간헐적으로 20초를 넘길 수 있습니다. fixedRate와 초기 지연을 두고, 값을 프로퍼티로 조정 가능하게 하는 것을 권장합니다.
아래와 같이 주석을 더 정확히 하고, 스케줄 애노테이션을 프로퍼티 기반으로 바꾸는 것을 제안합니다.
- // 15초마다 실행 (ActiveMQ TTL인 20초보다 짧게 설정) - @Scheduled(fixedDelay = 15000) + // 기본 15초 간격(브로커 inactivity timeout보다 짧게), 초기 지연 5초. 프로퍼티로 조정 가능 + @Scheduled( + fixedRateString = "${stomp.keepalive.interval-ms:15000}", + initialDelayString = "${stomp.keepalive.initial-delay-ms:5000}" + )참고:
- fixedRate는 실행 시작 시각 기준으로 주기 유지 → 일시 지연 영향 완화
- 운영 환경별로 간격을 빠르게 조정 가능
19-20: 브로커 릴레이 프리픽스와 접근 제어를 점검하세요.
- 이 메시지가 ActiveMQ로 실제 전달되어야 효과가 있으므로, 메시지 브로커 설정에서 enableStompBrokerRelay("/topic", "/queue") 등으로 /topic이 릴레이 프리픽스로 설정되어 있는지 확인이 필요합니다. SimpleBroker만 쓰고 있다면 ActiveMQ 연결 유지에 영향을 주지 않습니다.
- 클라이언트에게 불필요한 "ping"이 전달되지 않도록, 메시지 보안 설정에서 해당 토픽 구독을 차단하는 것도 고려해 주세요(운영 노이즈 방지).
예시(스프링 메시지 보안 사용 시):
@Override protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) { messages .simpSubscribeDestMatchers("/topic/keep-alive").denyAll() // 내부 전용 .anyMessage().authenticated(); }
18-20: 전송 실패 추적을 위한 가벼운 로그/예외 처리 제안(선택).운영 트러블슈팅을 위해 DEBUG/TRACE 로그를 남기고, 드물게 발생 가능한 MessageDeliveryException 등을 캐치해 경고 로그로 남기는 것을 권장합니다.
예시:
// 클래스 필드/임포트(예시) // import lombok.extern.slf4j.Slf4j; // @Slf4j public void sendKeepAliveMessage() { try { this.messagingTemplate.convertAndSend("/topic/keep-alive", "ping"); // log.trace("STOMP keep-alive sent"); } catch (Exception e) { // log.warn("STOMP keep-alive send failed", e); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/main/java/org/ezcode/codetest/infrastructure/scheduler/StompKeepAliveScheduler.java(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (2)
src/main/java/org/ezcode/codetest/infrastructure/scheduler/StompKeepAliveScheduler.java (2)
7-14: LGTM: 컴포넌트 등록과 생성자 주입이 명확합니다.
- @component + 생성자 주입 + final 필드 구성은 적절합니다. 불변 필드로 스레드 안정성 측면에서도 좋습니다.
1-6: @EnableScheduling이 이미 활성화되어 있습니다
src/main/java/org/ezcode/codetest/CodetestApplication.java11번째 줄에@EnableScheduling이 선언되어 있어 스케줄링이 정상적으로 동작합니다. 별도의 추가 설정 클래스는 필요 없습니다.
작업 내용
참고 사항
Summary by CodeRabbit