File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
src/main/java/com/back/domain/websocket/config Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ repositories {
2727dependencies {
2828 implementation(" org.springframework.boot:spring-boot-starter-data-jpa" )
2929 implementation(" org.springframework.boot:spring-boot-starter-web" )
30+ implementation(" org.springframework.boot:spring-boot-starter-websocket" )
3031 implementation(" org.springframework.boot:spring-boot-starter-security" )
3132 testImplementation(" org.springframework.security:spring-security-test" )
3233 compileOnly(" org.projectlombok:lombok" )
Original file line number Diff line number Diff line change 1+ package com .back .domain .websocket .config ;
2+
3+ import org .springframework .context .annotation .Configuration ;
4+ import org .springframework .messaging .simp .config .MessageBrokerRegistry ;
5+ import org .springframework .web .socket .config .annotation .EnableWebSocketMessageBroker ;
6+ import org .springframework .web .socket .config .annotation .StompEndpointRegistry ;
7+ import org .springframework .web .socket .config .annotation .WebSocketMessageBrokerConfigurer ;
8+
9+ @ Configuration
10+ @ EnableWebSocketMessageBroker
11+ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
12+
13+ /**
14+ * 메시지 브로커 설정
15+ * - /topic: 1:N 브로드캐스트 (방 채팅)
16+ * - /queue: 1:1 메시지 (개인 DM)
17+ * - /app: 클라이언트에서 서버로 메시지 전송 시 prefix
18+ */
19+ @ Override
20+ public void configureMessageBroker (MessageBrokerRegistry config ) {
21+ config .enableSimpleBroker ("/topic" , "/queue" );
22+ config .setApplicationDestinationPrefixes ("/app" );
23+ config .setUserDestinationPrefix ("/user" );
24+ }
25+
26+ /**
27+ * STOMP 엔드포인트 등록
28+ * 클라이언트가 WebSocket 연결을 위해 사용할 엔드포인트
29+ */
30+ @ Override
31+ public void registerStompEndpoints (StompEndpointRegistry registry ) {
32+ registry .addEndpoint ("/ws" )
33+ .setAllowedOriginPatterns ("*" ) // 모든 도메인 허용 (개발용)
34+ .withSockJS (); // SockJS 사용
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments