From 4463eed82686ec6ce63cbcc973d6299f75d05bf5 Mon Sep 17 00:00:00 2001 From: jacknie Date: Tue, 18 Jan 2022 18:21:05 +0900 Subject: [PATCH] Modify Stomp -> RSocket --- backend-spring/.idea/gradle.xml | 3 -- backend-spring/build.gradle.kts | 43 ++++++++--------- backend-spring/domain/build.gradle.kts | 1 - backend-spring/rest-api/build.gradle.kts | 8 ---- backend-spring/settings.gradle.kts | 4 -- .../kotlin/com/jacknie/sample/chat/App.kt} | 0 .../chat/config/WebFluxConfiguration.kt | 4 +- .../jacknie/sample/chat/model/ChatCategory.kt | 0 .../sample/chat/model/ChatCategoryFilter.kt | 0 .../com/jacknie/sample/chat/model/ChatRoom.kt | 0 .../sample/chat/model/ChatRoomFilter.kt | 0 .../jacknie/sample/chat/model/UserSummary.kt | 0 .../ChatCategoryCustomRepository.kt | 0 .../chat/repository/ChatCategoryRepository.kt | 0 .../repository/ChatRoomCustomRepository.kt | 0 .../chat/repository/ChatRoomRepository.kt | 0 .../impl/ChatCategoryCustomRepositoryImpl.kt | 0 .../impl/ChatRoomCustomRepositoryImpl.kt | 0 .../chat/rsocket/controller/TestController.kt | 14 ++++++ .../webflux}/handler/ChatCategoryHandler.kt | 2 +- .../chat/webflux}/handler/ChatRoomHandler.kt | 2 +- .../webflux}/handler/CreateChatCategory.kt | 2 +- .../chat/webflux}/handler/CreateChatRoom.kt | 2 +- .../chat/webflux}/handler/SugarCodes.kt | 2 +- .../chat/webflux}/handler/Validation.kt | 2 +- .../src/main/resources/application.properties | 3 ++ .../src/main/resources/data.sql | 0 .../src/main/resources/schema.sql | 0 backend-spring/stomp-broker/build.gradle.kts | 3 -- .../com/jacknie/sample/chat/StompBrokerApp.kt | 11 ----- .../WebSocketMessageBrokerConfiguration.kt | 24 ---------- .../sample/chat/controller/ChatController.kt | 16 ------- .../src/main/resources/application.properties | 1 - frontend-react/components/ChatRooms/index.tsx | 48 ++++++++++++++++++- frontend-react/package.json | 4 ++ 35 files changed, 95 insertions(+), 104 deletions(-) delete mode 100644 backend-spring/domain/build.gradle.kts delete mode 100644 backend-spring/rest-api/build.gradle.kts rename backend-spring/{rest-api/src/main/kotlin/com/jacknie/sample/chat/RestApiApp.kt => src/main/kotlin/com/jacknie/sample/chat/App.kt} (100%) rename backend-spring/{rest-api => }/src/main/kotlin/com/jacknie/sample/chat/config/WebFluxConfiguration.kt (91%) rename backend-spring/{rest-api => }/src/main/kotlin/com/jacknie/sample/chat/model/ChatCategory.kt (100%) rename backend-spring/{rest-api => }/src/main/kotlin/com/jacknie/sample/chat/model/ChatCategoryFilter.kt (100%) rename backend-spring/{rest-api => }/src/main/kotlin/com/jacknie/sample/chat/model/ChatRoom.kt (100%) rename backend-spring/{rest-api => }/src/main/kotlin/com/jacknie/sample/chat/model/ChatRoomFilter.kt (100%) rename backend-spring/{rest-api => }/src/main/kotlin/com/jacknie/sample/chat/model/UserSummary.kt (100%) rename backend-spring/{rest-api => }/src/main/kotlin/com/jacknie/sample/chat/repository/ChatCategoryCustomRepository.kt (100%) rename backend-spring/{rest-api => }/src/main/kotlin/com/jacknie/sample/chat/repository/ChatCategoryRepository.kt (100%) rename backend-spring/{rest-api => }/src/main/kotlin/com/jacknie/sample/chat/repository/ChatRoomCustomRepository.kt (100%) rename backend-spring/{rest-api => }/src/main/kotlin/com/jacknie/sample/chat/repository/ChatRoomRepository.kt (100%) rename backend-spring/{rest-api => }/src/main/kotlin/com/jacknie/sample/chat/repository/impl/ChatCategoryCustomRepositoryImpl.kt (100%) rename backend-spring/{rest-api => }/src/main/kotlin/com/jacknie/sample/chat/repository/impl/ChatRoomCustomRepositoryImpl.kt (100%) create mode 100644 backend-spring/src/main/kotlin/com/jacknie/sample/chat/rsocket/controller/TestController.kt rename backend-spring/{rest-api/src/main/kotlin/com/jacknie/sample/chat => src/main/kotlin/com/jacknie/sample/chat/webflux}/handler/ChatCategoryHandler.kt (98%) rename backend-spring/{rest-api/src/main/kotlin/com/jacknie/sample/chat => src/main/kotlin/com/jacknie/sample/chat/webflux}/handler/ChatRoomHandler.kt (98%) rename backend-spring/{rest-api/src/main/kotlin/com/jacknie/sample/chat => src/main/kotlin/com/jacknie/sample/chat/webflux}/handler/CreateChatCategory.kt (86%) rename backend-spring/{rest-api/src/main/kotlin/com/jacknie/sample/chat => src/main/kotlin/com/jacknie/sample/chat/webflux}/handler/CreateChatRoom.kt (91%) rename backend-spring/{rest-api/src/main/kotlin/com/jacknie/sample/chat => src/main/kotlin/com/jacknie/sample/chat/webflux}/handler/SugarCodes.kt (96%) rename backend-spring/{rest-api/src/main/kotlin/com/jacknie/sample/chat => src/main/kotlin/com/jacknie/sample/chat/webflux}/handler/Validation.kt (97%) rename backend-spring/{rest-api => }/src/main/resources/application.properties (81%) rename backend-spring/{rest-api => }/src/main/resources/data.sql (100%) rename backend-spring/{rest-api => }/src/main/resources/schema.sql (100%) delete mode 100644 backend-spring/stomp-broker/build.gradle.kts delete mode 100644 backend-spring/stomp-broker/src/main/kotlin/com/jacknie/sample/chat/StompBrokerApp.kt delete mode 100644 backend-spring/stomp-broker/src/main/kotlin/com/jacknie/sample/chat/config/WebSocketMessageBrokerConfiguration.kt delete mode 100644 backend-spring/stomp-broker/src/main/kotlin/com/jacknie/sample/chat/controller/ChatController.kt delete mode 100644 backend-spring/stomp-broker/src/main/resources/application.properties diff --git a/backend-spring/.idea/gradle.xml b/backend-spring/.idea/gradle.xml index 55c30c0..ab9c25b 100644 --- a/backend-spring/.idea/gradle.xml +++ b/backend-spring/.idea/gradle.xml @@ -11,9 +11,6 @@ diff --git a/backend-spring/build.gradle.kts b/backend-spring/build.gradle.kts index edeba7b..1c8b064 100644 --- a/backend-spring/build.gradle.kts +++ b/backend-spring/build.gradle.kts @@ -7,35 +7,30 @@ plugins { kotlin("plugin.spring") version "1.6.10" } -allprojects { - repositories { - mavenCentral() - } +repositories { + mavenCentral() } -subprojects { - - apply { plugin("org.gradle.application") } - apply { plugin("org.gradle.idea") } - apply { plugin("org.springframework.boot") } - apply { plugin("io.spring.dependency-management") } - apply { plugin("org.jetbrains.kotlin.jvm") } - apply { plugin("org.jetbrains.kotlin.plugin.spring") } +dependencies { + implementation(platform(kotlin("bom"))) + implementation(kotlin("stdlib")) + implementation(kotlin("reflect")) + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + implementation("org.springframework.boot:spring-boot-starter-webflux") + implementation("org.springframework.boot:spring-boot-starter-rsocket") + implementation("org.springframework.boot:spring-boot-starter-data-r2dbc") + implementation("org.hibernate.validator:hibernate-validator") + implementation("io.r2dbc:r2dbc-h2") - dependencies { - implementation(platform(kotlin("bom"))) - implementation(kotlin("stdlib")) - implementation(kotlin("reflect")) - implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + runtimeOnly("com.h2database:h2") - developmentOnly("org.springframework.boot:spring-boot-devtools") - } + developmentOnly("org.springframework.boot:spring-boot-devtools") +} - tasks.withType { - kotlinOptions { - freeCompilerArgs = freeCompilerArgs + listOf("-Xjsr305=strict", "-Xemit-jvm-type-annotations") - jvmTarget = "11" - } +tasks.withType { + kotlinOptions { + freeCompilerArgs = freeCompilerArgs + listOf("-Xjsr305=strict", "-Xemit-jvm-type-annotations") + jvmTarget = "11" } } diff --git a/backend-spring/domain/build.gradle.kts b/backend-spring/domain/build.gradle.kts deleted file mode 100644 index 8b13789..0000000 --- a/backend-spring/domain/build.gradle.kts +++ /dev/null @@ -1 +0,0 @@ - diff --git a/backend-spring/rest-api/build.gradle.kts b/backend-spring/rest-api/build.gradle.kts deleted file mode 100644 index 12b7bad..0000000 --- a/backend-spring/rest-api/build.gradle.kts +++ /dev/null @@ -1,8 +0,0 @@ -dependencies { - implementation("org.springframework.boot:spring-boot-starter-webflux") - implementation("org.springframework.boot:spring-boot-starter-data-r2dbc") - implementation("org.hibernate.validator:hibernate-validator") - implementation("io.r2dbc:r2dbc-h2") - - runtimeOnly("com.h2database:h2") -} diff --git a/backend-spring/settings.gradle.kts b/backend-spring/settings.gradle.kts index 8bbefbc..5ead7e8 100644 --- a/backend-spring/settings.gradle.kts +++ b/backend-spring/settings.gradle.kts @@ -8,7 +8,3 @@ */ rootProject.name = "backend-spring" - -include("rest-api") -include("stomp-broker") -include("domain") diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/RestApiApp.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/App.kt similarity index 100% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/RestApiApp.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/App.kt diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/config/WebFluxConfiguration.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/config/WebFluxConfiguration.kt similarity index 91% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/config/WebFluxConfiguration.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/config/WebFluxConfiguration.kt index d50054a..e4b7a65 100644 --- a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/config/WebFluxConfiguration.kt +++ b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/config/WebFluxConfiguration.kt @@ -1,7 +1,7 @@ package com.jacknie.sample.chat.config -import com.jacknie.sample.chat.handler.ChatCategoryHandler -import com.jacknie.sample.chat.handler.ChatRoomHandler +import com.jacknie.sample.chat.webflux.handler.ChatCategoryHandler +import com.jacknie.sample.chat.webflux.handler.ChatRoomHandler import org.springframework.beans.factory.annotation.Qualifier import org.springframework.boot.web.codec.CodecCustomizer import org.springframework.context.annotation.Bean diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/model/ChatCategory.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/model/ChatCategory.kt similarity index 100% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/model/ChatCategory.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/model/ChatCategory.kt diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/model/ChatCategoryFilter.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/model/ChatCategoryFilter.kt similarity index 100% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/model/ChatCategoryFilter.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/model/ChatCategoryFilter.kt diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/model/ChatRoom.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/model/ChatRoom.kt similarity index 100% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/model/ChatRoom.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/model/ChatRoom.kt diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/model/ChatRoomFilter.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/model/ChatRoomFilter.kt similarity index 100% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/model/ChatRoomFilter.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/model/ChatRoomFilter.kt diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/model/UserSummary.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/model/UserSummary.kt similarity index 100% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/model/UserSummary.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/model/UserSummary.kt diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/repository/ChatCategoryCustomRepository.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/repository/ChatCategoryCustomRepository.kt similarity index 100% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/repository/ChatCategoryCustomRepository.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/repository/ChatCategoryCustomRepository.kt diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/repository/ChatCategoryRepository.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/repository/ChatCategoryRepository.kt similarity index 100% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/repository/ChatCategoryRepository.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/repository/ChatCategoryRepository.kt diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/repository/ChatRoomCustomRepository.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/repository/ChatRoomCustomRepository.kt similarity index 100% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/repository/ChatRoomCustomRepository.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/repository/ChatRoomCustomRepository.kt diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/repository/ChatRoomRepository.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/repository/ChatRoomRepository.kt similarity index 100% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/repository/ChatRoomRepository.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/repository/ChatRoomRepository.kt diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/repository/impl/ChatCategoryCustomRepositoryImpl.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/repository/impl/ChatCategoryCustomRepositoryImpl.kt similarity index 100% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/repository/impl/ChatCategoryCustomRepositoryImpl.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/repository/impl/ChatCategoryCustomRepositoryImpl.kt diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/repository/impl/ChatRoomCustomRepositoryImpl.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/repository/impl/ChatRoomCustomRepositoryImpl.kt similarity index 100% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/repository/impl/ChatRoomCustomRepositoryImpl.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/repository/impl/ChatRoomCustomRepositoryImpl.kt diff --git a/backend-spring/src/main/kotlin/com/jacknie/sample/chat/rsocket/controller/TestController.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/rsocket/controller/TestController.kt new file mode 100644 index 0000000..f3dc428 --- /dev/null +++ b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/rsocket/controller/TestController.kt @@ -0,0 +1,14 @@ +package com.jacknie.sample.chat.rsocket.controller + +import org.springframework.messaging.handler.annotation.MessageMapping +import org.springframework.stereotype.Controller + +@Controller +class TestController { + + @MessageMapping("request-response") + fun echo(request: String): String { + return request + } + +} diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/ChatCategoryHandler.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/ChatCategoryHandler.kt similarity index 98% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/ChatCategoryHandler.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/ChatCategoryHandler.kt index e4319d4..f933cb1 100644 --- a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/ChatCategoryHandler.kt +++ b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/ChatCategoryHandler.kt @@ -1,4 +1,4 @@ -package com.jacknie.sample.chat.handler +package com.jacknie.sample.chat.webflux.handler import com.jacknie.sample.chat.model.ChatCategory import com.jacknie.sample.chat.model.ChatCategoryFilter diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/ChatRoomHandler.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/ChatRoomHandler.kt similarity index 98% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/ChatRoomHandler.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/ChatRoomHandler.kt index d3d0037..d8b827a 100644 --- a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/ChatRoomHandler.kt +++ b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/ChatRoomHandler.kt @@ -1,4 +1,4 @@ -package com.jacknie.sample.chat.handler +package com.jacknie.sample.chat.webflux.handler import com.jacknie.sample.chat.model.ChatRoom import com.jacknie.sample.chat.model.ChatRoomFilter diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/CreateChatCategory.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/CreateChatCategory.kt similarity index 86% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/CreateChatCategory.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/CreateChatCategory.kt index f5fc839..92ebe32 100644 --- a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/CreateChatCategory.kt +++ b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/CreateChatCategory.kt @@ -1,4 +1,4 @@ -package com.jacknie.sample.chat.handler +package com.jacknie.sample.chat.webflux.handler import javax.validation.constraints.NotBlank import javax.validation.constraints.Positive diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/CreateChatRoom.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/CreateChatRoom.kt similarity index 91% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/CreateChatRoom.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/CreateChatRoom.kt index 18d76ce..f3f4486 100644 --- a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/CreateChatRoom.kt +++ b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/CreateChatRoom.kt @@ -1,4 +1,4 @@ -package com.jacknie.sample.chat.handler +package com.jacknie.sample.chat.webflux.handler import javax.validation.constraints.NotBlank import javax.validation.constraints.NotNull diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/SugarCodes.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/SugarCodes.kt similarity index 96% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/SugarCodes.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/SugarCodes.kt index e23b257..90504fd 100644 --- a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/SugarCodes.kt +++ b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/SugarCodes.kt @@ -1,4 +1,4 @@ -package com.jacknie.sample.chat.handler +package com.jacknie.sample.chat.webflux.handler import org.springframework.data.domain.Page import org.springframework.data.domain.PageRequest diff --git a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/Validation.kt b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/Validation.kt similarity index 97% rename from backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/Validation.kt rename to backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/Validation.kt index 16c3faf..b7bd485 100644 --- a/backend-spring/rest-api/src/main/kotlin/com/jacknie/sample/chat/handler/Validation.kt +++ b/backend-spring/src/main/kotlin/com/jacknie/sample/chat/webflux/handler/Validation.kt @@ -1,4 +1,4 @@ -package com.jacknie.sample.chat.handler +package com.jacknie.sample.chat.webflux.handler import org.springframework.http.HttpStatus import org.springframework.stereotype.Component diff --git a/backend-spring/rest-api/src/main/resources/application.properties b/backend-spring/src/main/resources/application.properties similarity index 81% rename from backend-spring/rest-api/src/main/resources/application.properties rename to backend-spring/src/main/resources/application.properties index 3d46d6f..ecbc02a 100644 --- a/backend-spring/rest-api/src/main/resources/application.properties +++ b/backend-spring/src/main/resources/application.properties @@ -5,6 +5,9 @@ spring.r2dbc.password= spring.sql.init.mode=embedded +spring.rsocket.server.port=9080 +spring.rsocket.server.transport=websocket + server.port=8080 logging.level.org.springframework.r2dbc=DEBUG diff --git a/backend-spring/rest-api/src/main/resources/data.sql b/backend-spring/src/main/resources/data.sql similarity index 100% rename from backend-spring/rest-api/src/main/resources/data.sql rename to backend-spring/src/main/resources/data.sql diff --git a/backend-spring/rest-api/src/main/resources/schema.sql b/backend-spring/src/main/resources/schema.sql similarity index 100% rename from backend-spring/rest-api/src/main/resources/schema.sql rename to backend-spring/src/main/resources/schema.sql diff --git a/backend-spring/stomp-broker/build.gradle.kts b/backend-spring/stomp-broker/build.gradle.kts deleted file mode 100644 index 2b8dfe7..0000000 --- a/backend-spring/stomp-broker/build.gradle.kts +++ /dev/null @@ -1,3 +0,0 @@ -dependencies { - implementation("org.springframework.boot:spring-boot-starter-websocket") -} diff --git a/backend-spring/stomp-broker/src/main/kotlin/com/jacknie/sample/chat/StompBrokerApp.kt b/backend-spring/stomp-broker/src/main/kotlin/com/jacknie/sample/chat/StompBrokerApp.kt deleted file mode 100644 index f0d2026..0000000 --- a/backend-spring/stomp-broker/src/main/kotlin/com/jacknie/sample/chat/StompBrokerApp.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.jacknie.sample.chat - -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.boot.runApplication - -@SpringBootApplication -class StompBrokerApp - -fun main() { - runApplication() -} diff --git a/backend-spring/stomp-broker/src/main/kotlin/com/jacknie/sample/chat/config/WebSocketMessageBrokerConfiguration.kt b/backend-spring/stomp-broker/src/main/kotlin/com/jacknie/sample/chat/config/WebSocketMessageBrokerConfiguration.kt deleted file mode 100644 index 2a074c2..0000000 --- a/backend-spring/stomp-broker/src/main/kotlin/com/jacknie/sample/chat/config/WebSocketMessageBrokerConfiguration.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.jacknie.sample.chat.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 -class WebSocketMessageBrokerConfiguration : WebSocketMessageBrokerConfigurer { - - override fun registerStompEndpoints(registry: StompEndpointRegistry) { - registry.addEndpoint("/chat") - .setAllowedOrigins("http://localhost:3000") - .withSockJS() - } - - override fun configureMessageBroker(registry: MessageBrokerRegistry) { - registry.enableSimpleBroker("/topic/", "/queue/") - registry.setApplicationDestinationPrefixes("/chat/") - } - -} diff --git a/backend-spring/stomp-broker/src/main/kotlin/com/jacknie/sample/chat/controller/ChatController.kt b/backend-spring/stomp-broker/src/main/kotlin/com/jacknie/sample/chat/controller/ChatController.kt deleted file mode 100644 index 0524a23..0000000 --- a/backend-spring/stomp-broker/src/main/kotlin/com/jacknie/sample/chat/controller/ChatController.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.jacknie.sample.chat.controller - -import org.springframework.messaging.handler.annotation.MessageMapping -import org.springframework.messaging.handler.annotation.SendTo -import org.springframework.stereotype.Controller - -@Controller -class ChatController { - - @MessageMapping("/echo") - @SendTo("/topic/echo") - fun echo(message: String): String { - return message - } - -} diff --git a/backend-spring/stomp-broker/src/main/resources/application.properties b/backend-spring/stomp-broker/src/main/resources/application.properties deleted file mode 100644 index f59ffea..0000000 --- a/backend-spring/stomp-broker/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -server.port=9080 diff --git a/frontend-react/components/ChatRooms/index.tsx b/frontend-react/components/ChatRooms/index.tsx index 7ba3187..7d52e41 100644 --- a/frontend-react/components/ChatRooms/index.tsx +++ b/frontend-react/components/ChatRooms/index.tsx @@ -1,5 +1,12 @@ import { Button, Pagination, Stack } from "@mui/material"; -import { useMemo, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; +import { + Encodable, + IdentitySerializer, + JsonSerializer, + RSocketClient, +} from "rsocket-core"; +import RSocketWebsocketClient from "rsocket-websocket-client"; import { PageRequest, SortRequest } from "types"; import ChatRoomList from "./ChatRoomList"; import useChatRooms from "./hooks/chat-rooms"; @@ -12,6 +19,7 @@ const basePageRequest = { }; function ChatRooms() { + useTestRSocket(); const [totalCount, setTotalCount] = useState(0); const pageSize = useMemo( () => @@ -44,4 +52,42 @@ function ChatRooms() { ); } +function useTestRSocket() { + const rsocketClient = useMemo(() => createRSocketClient(), []); + + useEffect(() => { + rsocketClient.then(client => { + client + .requestResponse({ + data: { value: "Hello RSocket!!" }, + metadata: + String.fromCharCode("request-response".length) + "request-response", + }) + .subscribe({ + onComplete: value => console.log(value), + onError: error => console.error(error), + onSubscribe: cancel => {}, + }); + }); + }, [rsocketClient]); +} + +function createRSocketClient() { + const transport = new RSocketWebsocketClient({ url: "ws://localhost:9080" }); + const client = new RSocketClient({ + serializers: { + data: JsonSerializer, + metadata: IdentitySerializer, + }, + setup: { + keepAlive: 1000000, + lifetime: 100000, + dataMimeType: "application/json", + metadataMimeType: "message/x.rsocket.routing.v0", + }, + transport, + }); + return client.connect(); +} + export default ChatRooms; diff --git a/frontend-react/package.json b/frontend-react/package.json index 0749a80..e21e724 100644 --- a/frontend-react/package.json +++ b/frontend-react/package.json @@ -13,12 +13,16 @@ "@mui/material": "^5.2.8", "@stomp/stompjs": "^6.1.2", "@types/lodash": "^4.14.178", + "@types/rsocket-core": "^0.0.7", + "@types/rsocket-websocket-client": "^0.0.4", "@types/sockjs-client": "^1.5.1", "lodash": "^4.17.21", "next": "12.0.7", "react": "17.0.2", "react-dom": "17.0.2", "react-hook-form": "^7.24.0", + "rsocket-core": "^0.0.27", + "rsocket-websocket-client": "^0.0.27", "sockjs-client": "^1.5.2", "swr": "^1.1.2", "websocket": "^1.0.34"