{"id":35158,"date":"2023-05-28T11:29:56","date_gmt":"2023-05-28T02:29:56","guid":{"rendered":"https:\/\/m9js.shop\/blog\/?p=35158"},"modified":"2023-05-28T11:29:56","modified_gmt":"2023-05-28T02:29:56","slug":"implementing-real-time-collaboration-with-spring-boot-and-websockets","status":"publish","type":"post","link":"https:\/\/m9js.shop\/blog\/development\/implementing-real-time-collaboration-with-spring-boot-and-websockets","title":{"rendered":"Implementing Real-Time Collaboration with Spring Boot and WebSockets"},"content":{"rendered":"

\uc2a4\ud504\ub9c1 \ubd80\ud2b8\uc640 \uc6f9\uc18c\ucf13\uc73c\ub85c \uc2e4\uc2dc\uac04 \ud611\uc5c5 \uad6c\ud604\ud558\uae30<\/h1>\n

\uc2e4\uc2dc\uac04 \ud611\uc5c5\uc740 \ubaa8\ub4e0 \uc5c5\ubb34\uc5d0\uc11c \uc911\uc694\ud55c \uc5ed\ud560\uc744 \ud569\ub2c8\ub2e4. \uc774\ub97c \uc704\ud574 \ub9ce\uc740 \uae30\uc5c5\ub4e4\uc740 \ub2e4\uc591\ud55c \uc194\ub8e8\uc158\uc744 \uc0ac\uc6a9\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ubc88 \uae00\uc5d0\uc11c\ub294 \uc2a4\ud504\ub9c1 \ubd80\ud2b8\uc640 \uc6f9\uc18c\ucf13\uc744 \uc774\uc6a9\ud558\uc5ec \uc2e4\uc2dc\uac04 \ud611\uc5c5\uc744 \uad6c\ud604\ud558\ub294 \ubc29\ubc95\uc5d0 \ub300\ud574 \uc54c\uc544\ubcf4\uaca0\uc2b5\ub2c8\ub2e4. \uc2a4\ud504\ub9c1 \ubd80\ud2b8\ub294 \uc790\ubc14 \uae30\ubc18\uc758 \ud504\ub808\uc784\uc6cc\ud06c\ub85c, \uc6f9\uc18c\ucf13\uc740 \uc11c\ubc84\uc640 \ud074\ub77c\uc774\uc5b8\ud2b8 \uac04 \uc591\ubc29\ud5a5 \ud1b5\uc2e0\uc744 \uac00\ub2a5\ud558\uac8c \ud558\ub294 \ud504\ub85c\ud1a0\ucf5c\uc785\ub2c8\ub2e4.<\/p>\n

\uc6f9\uc18c\ucf13\uacfc SockJS\ub97c \uc0ac\uc6a9\ud558\uc5ec \ud074\ub77c\uc774\uc5b8\ud2b8\uc640 \uc11c\ubc84\uac04 \uc5f0\uacb0 \uad6c\uc131\ud558\uae30<\/h2>\n

\uc6f9\uc18c\ucf13\uc744 \uc774\uc6a9\ud558\uc5ec \ud074\ub77c\uc774\uc5b8\ud2b8\uc640 \uc11c\ubc84\uac04\uc758 \uc2e4\uc2dc\uac04 \ud1b5\uc2e0\uc744 \uad6c\ud604\ud558\uae30 \uc704\ud574\uc11c\ub294 \uba3c\uc800 \uc6f9\uc18c\ucf13 \uc5f0\uacb0\uc744 \uc124\uc815\ud574\uc57c \ud569\ub2c8\ub2e4. \uc774\ub97c \uc704\ud574 SockJS\ub97c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. SockJS\ub294 \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c \uc6f9\uc18c\ucf13\uc744 \uc9c0\uc6d0\ud558\uc9c0 \uc54a\uc744 \ub54c \ub300\uccb4\ud560 \uc218 \uc788\ub294 \uae30\uc220\uc785\ub2c8\ub2e4.<\/p>\n

@Configuration\n@EnableWebSocketMessageBroker\npublic class WebSocketConfig implements WebSocketMessageBrokerConfigurer {\n\n    @Override\n    public void configureMessageBroker(MessageBrokerRegistry config) {\n        config.enableSimpleBroker(\"\/topic\");\n        config.setApplicationDestinationPrefixes(\"\/app\");\n    }\n\n    @Override\n    public void registerStompEndpoints(StompEndpointRegistry registry) {\n        registry\n          .addEndpoint(\"\/ws\")\n          .setAllowedOrigins(\"*\")\n          .withSockJS();\n    }\n}<\/code><\/pre>\n

\uc704 \ucf54\ub4dc\ub294 \uc2a4\ud504\ub9c1 \ubd80\ud2b8\uc5d0\uc11c \uc6f9\uc18c\ucf13\uc744 \uc124\uc815\ud558\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4. configureMessageBroker()<\/code> \uba54\uc18c\ub4dc\uc5d0\uc11c enableSimpleBroker()<\/code>\ub97c \ud638\ucd9c\ud558\uc5ec \/topic<\/code>\uc73c\ub85c \uc2dc\uc791\ud558\ub294 \uba54\uc2dc\uc9c0\ub97c \uad6c\ub3c5\ud560 \uc218 \uc788\ub3c4\ub85d \uc124\uc815\ud558\uace0, setApplicationDestinationPrefixes()<\/code>\ub97c \ud638\ucd9c\ud558\uc5ec \/app<\/code>\uc73c\ub85c \uc2dc\uc791\ud558\ub294 \uba54\uc2dc\uc9c0\ub97c \ucc98\ub9ac\ud560 \uc218 \uc788\ub3c4\ub85d \uc124\uc815\ud569\ub2c8\ub2e4. \uadf8\ub9ac\uace0 registerStompEndpoints()<\/code> \uba54\uc18c\ub4dc\uc5d0\uc11c \/ws<\/code> \uc5d4\ub4dc\ud3ec\uc778\ud2b8\ub97c \ub4f1\ub85d\ud558\uace0, withSockJS()<\/code>\ub97c \ud638\ucd9c\ud558\uc5ec SockJS\ub97c \uc0ac\uc6a9\ud560 \uc218 \uc788\ub3c4\ub85d \uc124\uc815\ud569\ub2c8\ub2e4.<\/p>\n

STOMP \ud504\ub85c\ud1a0\ucf5c\uc744 \uc774\uc6a9\ud55c \uba54\uc2dc\uc9c0 \ube0c\ub85c\ucee4 \uad6c\ud604 \ubc0f \ub370\uc774\ud130 \uc804\uc1a1 \ucc98\ub9ac\ud558\uae30<\/h2>\n

STOMP\ub294 Simple Text Oriented Messaging Protocol\uc758 \uc57d\uc790\ub85c, \uc6f9\uc18c\ucf13\uc5d0\uc11c \uc0ac\uc6a9\ub418\ub294 \uba54\uc2dc\uc9c0 \ud504\ub85c\ud1a0\ucf5c\uc785\ub2c8\ub2e4. STOMP\ub97c \uc774\uc6a9\ud558\uc5ec \uba54\uc2dc\uc9c0 \ube0c\ub85c\ucee4\ub97c \uad6c\ud604\ud558\uace0, \ub370\uc774\ud130 \uc804\uc1a1\uc744 \ucc98\ub9ac\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n

@Controller\npublic class WebSocketController {\n\n    @MessageMapping(\"\/chat\")\n    @SendTo(\"\/topic\/messages\")\n    public WebSocketMessage chat(WebSocketMessage message) {\n        return new WebSocketMessage(\"[\" + message.getSender() + \"]: \" + message.getContent());\n    }\n}<\/code><\/pre>\n

\uc704 \ucf54\ub4dc\ub294 \/chat<\/code>\uc73c\ub85c \uc2dc\uc791\ud558\ub294 \uba54\uc2dc\uc9c0\ub97c \ucc98\ub9ac\ud558\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4. @MessageMapping<\/code> \uc5b4\ub178\ud14c\uc774\uc158\uc744 \uc774\uc6a9\ud558\uc5ec \/chat<\/code>\uc73c\ub85c \uc2dc\uc791\ud558\ub294 \uba54\uc2dc\uc9c0\ub97c \ucc98\ub9ac\ud560 \uc218 \uc788\ub3c4\ub85d \uc124\uc815\ud558\uace0, @SendTo<\/code> \uc5b4\ub178\ud14c\uc774\uc158\uc744 \uc774\uc6a9\ud558\uc5ec \/topic\/messages<\/code>\ub85c \uba54\uc2dc\uc9c0\ub97c \uc804\uc1a1\ud569\ub2c8\ub2e4.<\/p>\n

\ub9c8\ubb34\ub9ac<\/h2>\n

\uc704\uc5d0\uc11c \uc124\uba85\ud55c \ubc29\ubc95\uc744 \uc774\uc6a9\ud558\uc5ec \uc2a4\ud504\ub9c1 \ubd80\ud2b8\uc640 \uc6f9\uc18c\ucf13\uc744 \uc774\uc6a9\ud558\uc5ec \uc2e4\uc2dc\uac04 \ud611\uc5c5\uc744 \uad6c\ud604\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ub97c \uc774\uc6a9\ud558\uc5ec \ub2e4\uc591\ud55c \uc5c5\ubb34\uc5d0\uc11c \uc2e4\uc2dc\uac04 \ud611\uc5c5\uc744 \uad6c\ud604\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \ub610\ud55c, \uc2a4\ud504\ub9c1 \ubd80\ud2b8\uc640 \uc6f9\uc18c\ucf13\uc744 \uc774\uc6a9\ud558\uc5ec \uad6c\ud604\ud55c \uc2e4\uc2dc\uac04 \ud611\uc5c5\uc740 \ub2e4\uc591\ud55c \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c \ud638\ud658\ub418\ubbc0\ub85c, \ub354\uc6b1 \uc720\uc6a9\ud558\uac8c \uc0ac\uc6a9\ub420 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n

\"Real-Time<\/p>\n","protected":false},"excerpt":{"rendered":"

\uc2a4\ud504\ub9c1 \ubd80\ud2b8\uc640 \uc6f9\uc18c\ucf13\uc744 \uc774\uc6a9\ud55c \uc2e4\uc2dc\uac04 \ud611\uc5c5 \uad6c\ud604 \ubc29\ubc95\uc5d0 \ub300\ud574 \uc54c\uc544\ubcf4\uc790.<\/p>\n","protected":false},"author":1,"featured_media":12882,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1957],"tags":[5898,2059,2105,2188,97,2418,2156,5932],"class_list":["post-35158","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-backend","tag-implementing","tag-java","tag-public","tag-real","tag-real-time","tag-spring","tag-spring-boot"],"acf":[],"_links":{"self":[{"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/posts\/35158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/comments?post=35158"}],"version-history":[{"count":1,"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/posts\/35158\/revisions"}],"predecessor-version":[{"id":35168,"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/posts\/35158\/revisions\/35168"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/media\/12882"}],"wp:attachment":[{"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/media?parent=35158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/categories?post=35158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/tags?post=35158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}