Skip to content

Commit a4ed911

Browse files
committed
Feat: WebSocket 의존성 추가 + WebSocketConfig 구현 (#33)
1 parent eae41f4 commit a4ed911

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ repositories {
2727
dependencies {
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")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

0 commit comments

Comments
 (0)