{"id":34287,"date":"2023-05-20T21:15:28","date_gmt":"2023-05-20T12:15:28","guid":{"rendered":"https:\/\/m9js.shop\/blog\/?p=34287"},"modified":"2023-05-20T21:15:28","modified_gmt":"2023-05-20T12:15:28","slug":"responsive-web-application-development-using-spring-webflux-and-reactor","status":"publish","type":"post","link":"https:\/\/m9js.shop\/blog\/development\/responsive-web-application-development-using-spring-webflux-and-reactor","title":{"rendered":"\uc2a4\ud504\ub9c1 \uc6f9\ud50c\ub7ed\uc2a4\uc640 \ub9ac\uc561\ud130\ub97c \ud65c\uc6a9\ud55c \ubc18\uc751\ud615 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \uac1c\ubc1c"},"content":{"rendered":"

\uc2a4\ud504\ub9c1 \uc6f9\ud50c\ub7ed\uc2a4\uc640 \ub9ac\uc561\ud130\ub780?<\/h1>\n

\uc2a4\ud504\ub9c1 \uc6f9\ud50c\ub7ed\uc2a4\uc640 \ub9ac\uc561\ud130\ub294 \uc2a4\ud504\ub9c1 \ud504\ub808\uc784\uc6cc\ud06c\uc5d0\uc11c \uc81c\uacf5\ud558\ub294 \ubc18\uc751\ud615 \ud504\ub85c\uadf8\ub798\ubc0d\uc744 \uc9c0\uc6d0\ud558\ub294 \ub77c\uc774\ube0c\ub7ec\ub9ac\uc785\ub2c8\ub2e4. \uc774\ub97c \uc774\uc6a9\ud558\uc5ec \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc744 \uac1c\ubc1c\ud560 \uc218 \uc788\uc73c\uba70, \uc774\ub7ec\ud55c \uae30\uc220\uc740 \ucd5c\uadfc\uc5d0 \ub9ce\uc740 \uad00\uc2ec\uc744 \ubc1b\uace0 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n

\uc2a4\ud504\ub9c1 \uc6f9\ud50c\ub7ed\uc2a4\ub294 \uc2a4\ud504\ub9c1 5\ubd80\ud130 \ucd94\uac00\ub41c \uc6f9 \ud504\ub808\uc784\uc6cc\ud06c\ub85c, \ub17c\ube14\ub85c\ud0b9 I\/O\ub97c \uc774\uc6a9\ud558\uc5ec \ub192\uc740 \uc131\ub2a5\uc744 \uc81c\uacf5\ud569\ub2c8\ub2e4. \ub610\ud55c Reactive Streams\uc640 \ud638\ud658\ub418\uc5b4 \ub2e4\uc591\ud55c \ub17c\ube14\ub85c\ud0b9 \ub77c\uc774\ube0c\ub7ec\ub9ac\uc640 \ud568\uaed8 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n

\ub9ac\uc561\ud130\ub294 Reactive Streams\ub97c \uad6c\ud604\ud55c \ub77c\uc774\ube0c\ub7ec\ub9ac \uc911 \ud558\ub098\ub85c, \uc2a4\ud504\ub9c1 \ud504\ub85c\uc81d\ud2b8\uc5d0\uc11c\ub3c4 \uc0ac\uc6a9\ub418\uace0 \uc788\uc2b5\ub2c8\ub2e4. \ub9ac\uc561\ud130\ub294 Flux\uc640 Mono\ub77c\ub294 \ub450 \uac00\uc9c0 \uc720\ud615\uc758 \ub370\uc774\ud130 \ud0c0\uc785\uc744 \uc81c\uacf5\ud558\uc5ec, \ube44\ub3d9\uae30\uc801\uc778 \ub370\uc774\ud130 \ucc98\ub9ac\ub97c \uc9c0\uc6d0\ud569\ub2c8\ub2e4.<\/p>\n

\ubc18\uc751\ud615 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \uac1c\ubc1c\uc744 \uc704\ud55c \ud544\uc218 \uae30\uc220<\/h1>\n

\ubc18\uc751\ud615 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc744 \uac1c\ubc1c\ud558\uae30 \uc704\ud574\uc11c\ub294 \ub2e4\uc74c\uacfc \uac19\uc740 \uae30\uc220\ub4e4\uc774 \ud544\uc694\ud569\ub2c8\ub2e4.<\/p>\n

\ub17c\ube14\ub85c\ud0b9 I\/O<\/h2>\n

\ub17c\ube14\ub85c\ud0b9 I\/O\ub294 \uc785\ucd9c\ub825 \uc791\uc5c5\uc774 \uc644\ub8cc\ub420 \ub54c\uae4c\uc9c0 \ub300\uae30\ud558\uc9c0 \uc54a\uace0 \ub2e4\ub978 \uc791\uc5c5\uc744 \uc218\ud589\ud560 \uc218 \uc788\ub294 \ubc29\uc2dd\uc785\ub2c8\ub2e4. \uc774\ub97c \uc774\uc6a9\ud558\uc5ec \ub2e4\uc218\uc758 \ud074\ub77c\uc774\uc5b8\ud2b8\ub97c \ub3d9\uc2dc\uc5d0 \ucc98\ub9ac\ud560 \uc218 \uc788\uc73c\uba70, \ub192\uc740 \ucc98\ub9ac\ub7c9\uacfc \ub0ae\uc740 \uc9c0\uc5f0 \uc2dc\uac04\uc744 \uc81c\uacf5\ud569\ub2c8\ub2e4.<\/p>\n

Reactive Streams<\/h2>\n

Reactive Streams\ub294 \ube44\ub3d9\uae30\uc801\uc778 \uc2a4\ud2b8\ub9bc \ucc98\ub9ac\ub97c \uc704\ud55c API \uaddc\uaca9\uc785\ub2c8\ub2e4. Publisher, Subscriber, Subscription, Processor\ub77c\ub294 \ub124 \uac00\uc9c0 \uc778\ud130\ud398\uc774\uc2a4\ub85c \uc774\ub8e8\uc5b4\uc838 \uc788\uc73c\uba70, \uc774\ub97c \uc774\uc6a9\ud558\uc5ec \ub2e4\uc591\ud55c \ub17c\ube14\ub85c\ud0b9 \ub77c\uc774\ube0c\ub7ec\ub9ac\ub97c \ud568\uaed8 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n

Flux\uc640 Mono<\/h2>\n

Flux\uc640 Mono\ub294 \ub9ac\uc561\ud130\uc5d0\uc11c \uc81c\uacf5\ud558\ub294 \ub370\uc774\ud130 \ud0c0\uc785\uc73c\ub85c, \ube44\ub3d9\uae30\uc801\uc778 \ub370\uc774\ud130 \ucc98\ub9ac\ub97c \uc9c0\uc6d0\ud569\ub2c8\ub2e4. Flux\ub294 0\uac1c \uc774\uc0c1\uc758 \ub370\uc774\ud130\ub97c \ucc98\ub9ac\ud558\uba70, Mono\ub294 0\uac1c \ub610\ub294 1\uac1c\uc758 \ub370\uc774\ud130\ub97c \ucc98\ub9ac\ud569\ub2c8\ub2e4.<\/p>\n

\uc2a4\ud504\ub9c1 \uc6f9\ud50c\ub7ed\uc2a4\uc640 \ub9ac\uc561\ud130\ub97c \ud65c\uc6a9\ud55c \ubc18\uc751\ud615 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \uac1c\ubc1c \ubc29\ubc95<\/h1>\n

\uc2a4\ud504\ub9c1 \uc6f9\ud50c\ub7ed\uc2a4\uc640 \ub9ac\uc561\ud130\ub97c \uc774\uc6a9\ud558\uc5ec \ubc18\uc751\ud615 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc744 \uac1c\ubc1c\ud558\ub294 \ubc29\ubc95\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n

\ud504\ub85c\uc81d\ud2b8 \uc124\uc815<\/h2>\n

\uc2a4\ud504\ub9c1 \ubd80\ud2b8\ub97c \uc774\uc6a9\ud558\uc5ec \uc2a4\ud504\ub9c1 \uc6f9\ud50c\ub7ed\uc2a4\uc640 \ub9ac\uc561\ud130\ub97c \uc0ac\uc6a9\ud558\ub294 \ud504\ub85c\uc81d\ud2b8\ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4. \uc774\ub54c, Reactive Web\uacfc Reactive MongoDB \ub4f1\uc758 \uc758\uc874\uc131\uc744 \ucd94\uac00\ud569\ub2c8\ub2e4.<\/p>\n

dependencies {\n    implementation 'org.springframework.boot:spring-boot-starter-webflux'\n    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'\n}<\/code><\/pre>\n

\ub370\uc774\ud130 \ucc98\ub9ac<\/h2>\n

MongoDB\ub97c \uc774\uc6a9\ud558\uc5ec \ub370\uc774\ud130\ub97c \ucc98\ub9ac\ud558\ub294 \uc608\uc81c\ub97c \uc0b4\ud3b4\ubcf4\uaca0\uc2b5\ub2c8\ub2e4. \uba3c\uc800, Person\uc774\ub77c\ub294 \ub3c4\ud050\uba3c\ud2b8\ub97c \uc815\uc758\ud569\ub2c8\ub2e4.<\/p>\n

@Document\npublic class Person {\n    @Id\n    private String id;\n    private String name;\n    private int age;\n    \/\/ getter, setter, constructor\n}<\/code><\/pre>\n

\ub2e4\uc74c\uc73c\ub85c, ReactiveMongoRepository\ub97c \uc0c1\uc18d\ubc1b\uc544 PersonRepository\ub97c \uc815\uc758\ud569\ub2c8\ub2e4.<\/p>\n

public interface PersonRepository extends ReactiveMongoRepository {\n    Flux findByName(String name);\n}<\/code><\/pre>\n

\uc774\uc81c, PersonRepository\ub97c \uc774\uc6a9\ud558\uc5ec \ub370\uc774\ud130\ub97c \uc870\ud68c\ud558\ub294 \uc11c\ube44\uc2a4\ub97c \uc791\uc131\ud569\ub2c8\ub2e4.<\/p>\n

@Service\npublic class PersonService {\n    private final PersonRepository repository;\n\n    public PersonService(PersonRepository repository) {\n        this.repository = repository;\n    }\n\n    public Flux findByName(String name) {\n        return repository.findByName(name);\n    }\n}<\/code><\/pre>\n

API \ucc98\ub9ac<\/h2>\n

API \ucc98\ub9ac\ub294 RouterFunction\uacfc HandlerFunction\uc744 \uc774\uc6a9\ud558\uc5ec \uc791\uc131\ud569\ub2c8\ub2e4. \uba3c\uc800, RouterFunction\uc744 \uc815\uc758\ud569\ub2c8\ub2e4.<\/p>\n

@Configuration\npublic class PersonRouter {\n    @Bean\n    public RouterFunction personRoute(PersonHandler handler) {\n        return RouterFunctions.route()\n                .GET(\"\/person\/{name}\", accept(APPLICATION_JSON), handler::findByname)\n                .build();\n    }\n}<\/code><\/pre>\n

\ub2e4\uc74c\uc73c\ub85c, HandlerFunction\uc744 \uc815\uc758\ud569\ub2c8\ub2e4.<\/p>\n

@Component\npublic class PersonHandler {\n    private final PersonService service;\n\n    public PersonHandler(PersonService service) {\n        this.service = service;\n    }\n\n    public Mono findByname(ServerRequest request) {\n        String name = request.pathVariable(\"name\");\n        Flux people = service.findByName(name);\n        return ServerResponse.ok().body(people, Person.class);\n    }\n}<\/code><\/pre>\n

\uc2e4\ud589<\/h2>\n

\uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc744 \uc2e4\ud589\ud558\uace0, http:\/\/localhost:8080\/person\/{name<\/a>} \ud615\uc2dd\uc73c\ub85c \uc694\uccad\uc744 \ubcf4\ub0b4\uba74, \ud574\ub2f9 \uc774\ub984\uc744 \uac00\uc9c4 Person \ub370\uc774\ud130\ub97c \uc870\ud68c\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n

\uacb0\ub860<\/h1>\n

\uc2a4\ud504\ub9c1 \uc6f9\ud50c\ub7ed\uc2a4\uc640 \ub9ac\uc561\ud130\ub97c \uc774\uc6a9\ud558\uc5ec \ubc18\uc751\ud615 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc744 \uac1c\ubc1c\ud558\ub294 \ubc29\ubc95\uc5d0 \ub300\ud574 \uc54c\uc544\ubcf4\uc558\uc2b5\ub2c8\ub2e4. \uc774\ub97c \uc774\uc6a9\ud558\uc5ec \ub192\uc740 \uc131\ub2a5\uacfc \ud655\uc7a5\uc131\uc744 \uac00\uc9c4 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc744 \uac1c\ubc1c\ud560 \uc218 \uc788\uc73c\uba70, \uc774\ub7ec\ud55c \uae30\uc220\uc740 \ub2e4\uc591\ud55c \ubd84\uc57c\uc5d0\uc11c \ud65c\uc6a9\ub420 \uac83\uc73c\ub85c \uc608\uc0c1\ub429\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"

\uc2a4\ud504\ub9c1 \uc6f9\ud50c\ub7ed\uc2a4\uc640 \ub9ac\uc561\ud130\ub97c \ud65c\uc6a9\ud558\uc5ec \ubc18\uc751\ud615 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc744 \uac1c\ubc1c\ud558\ub294 \ubc29\ubc95\uc744 \uc54c\uc544\ubcf4\uc790.<\/p>\n","protected":false},"author":1,"featured_media":33704,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1957],"tags":[2119,2104,2188,2156,2144],"class_list":["post-34287","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-api","tag-data","tag-public","tag-spring","tag-web"],"acf":[],"_links":{"self":[{"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/posts\/34287","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=34287"}],"version-history":[{"count":1,"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/posts\/34287\/revisions"}],"predecessor-version":[{"id":34378,"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/posts\/34287\/revisions\/34378"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/media\/33704"}],"wp:attachment":[{"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/media?parent=34287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/categories?post=34287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/m9js.shop\/blog\/wp-json\/wp\/v2\/tags?post=34287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}