-
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.
Browse files
Browse the repository at this point in the history
Feature/#1
- Loading branch information
Showing
7 changed files
with
133 additions
and
0 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
25 changes: 25 additions & 0 deletions
25
src/main/java/io/urdego/urdego_gateway_service/config/GatewayConfig.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,25 @@ | ||
package io.urdego.urdego_gateway_service.config; | ||
|
||
import org.springframework.cloud.gateway.route.RouteLocator; | ||
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class GatewayConfig { | ||
|
||
@Bean | ||
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) { | ||
return builder.routes() | ||
// 알림 서비스로 라우팅 | ||
.route("notification-websocket-route", r -> r.path("/ws/notifications/**") | ||
.uri("ws://notification-service:8081")) // 알림 서비스 URI | ||
|
||
// 게임 서비스로 라우팅 | ||
.route("game-websocket-route", r -> r.path("/ws/games/**") | ||
.uri("ws://game-service:8082")) // 게임 서비스 URI | ||
|
||
// 기타 WebSocket 요청 처리 (필요하면 추가) | ||
.build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/io/urdego/urdego_gateway_service/config/WebSocketConfig.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,24 @@ | ||
package io.urdego.urdego_gateway_service.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; | ||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; | ||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; | ||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; | ||
|
||
@Configuration | ||
@EnableWebSocketMessageBroker | ||
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { | ||
|
||
@Override | ||
public void configureMessageBroker(MessageBrokerRegistry registry) { | ||
registry.enableSimpleBroker("/urdego/sub"); | ||
registry.setApplicationDestinationPrefixes("/urdego/pub"); | ||
} | ||
|
||
@Override | ||
public void registerStompEndpoints(StompEndpointRegistry registry) { | ||
registry.addEndpoint("/urdego/connect") | ||
.setAllowedOrigins("*"); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/io/urdego/urdego_gateway_service/controller/WebSocketController.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,58 @@ | ||
package io.urdego.urdego_gateway_service.controller; | ||
|
||
import io.urdego.urdego_gateway_service.dto.MessageInfo; | ||
import io.urdego.urdego_gateway_service.feign.game.dto.GameServiceFeignClient; | ||
import io.urdego.urdego_gateway_service.feign.notification.NotificationServiceFeignClient; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.messaging.handler.annotation.DestinationVariable; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.handler.annotation.SendTo; | ||
import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class WebSocketController { | ||
|
||
private final NotificationServiceFeignClient notificationServiceFeignClient; | ||
private final GameServiceFeignClient gameServiceFeignClient; | ||
private final SimpMessagingTemplate messagingTemplate; | ||
|
||
@MessageMapping("/message") | ||
@SendTo("/urdego/sub") | ||
public void handleMessage(MessageInfo message) { | ||
switch (message.type()) { | ||
case "알림 전송 요청": | ||
// 알림 서비스로 메시지 전달 각각 UserId | ||
notificationServiceFeignClient.sendNotification(message.payload()); | ||
break; | ||
|
||
case "안읽은 알림 불러오기": | ||
// 알림 서비스로 메시지 전달 | ||
notificationServiceFeignClient.sendNotification(message.payload()); | ||
break; | ||
|
||
case "JOIN_ROOM": | ||
// 방에 넣어버리는 메서드 | ||
gameServiceFeignClient.processGameEvent(message.payload()); | ||
break; | ||
case "START_GAME": | ||
// 게임 생성 및 시작 메서드 | ||
|
||
break; | ||
// case "CHAT": | ||
// // 메시지를 직접 브로드캐스트 | ||
// notificationServiceFeignClient.sendNotification(message.payload()); | ||
// messagingTemplate.convertAndSend("/urdego/sub/" + message.payload().userId(), message); | ||
// break; | ||
default: | ||
throw new IllegalArgumentException("Unsupported message type: " + message.type()); | ||
} | ||
} | ||
|
||
@MessageMapping("/message") | ||
@SendTo("/urdego/sub/{userId}") | ||
public void handleMessage2(MessageInfo message, @DestinationVariable String userId) { | ||
|
||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/io/urdego/urdego_gateway_service/dto/MessageInfo.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 io.urdego.urdego_gateway_service.dto; | ||
|
||
public record MessageInfo<T>( | ||
String type, | ||
T payload, | ||
String userId | ||
) { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/io/urdego/urdego_gateway_service/feign/game/dto/GameServiceFeignClient.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,4 @@ | ||
package io.urdego.urdego_gateway_service.feign.game.dto; | ||
|
||
public interface GameServiceFeignClient { | ||
} |
11 changes: 11 additions & 0 deletions
11
...a/io/urdego/urdego_gateway_service/feign/notification/NotificationServiceFeignClient.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,11 @@ | ||
package io.urdego.urdego_gateway_service.feign.notification; | ||
|
||
public interface NotificationServiceFeignClient { | ||
//Notification의 모든 API | ||
|
||
// 알림 전송 | ||
|
||
// 알림 확인 시 게임방으로 이동 | ||
|
||
|
||
} |